source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/hash_utils.rb | Ruby | mit | 88 | master | 330 | module Chassis
module HashUtils
def symbolize(hash)
hash.inject({}) do |memo, pair|
key, value = pair
if value.is_a? Hash
memo.merge! key.to_sym => symbolize(value)
else
memo.merge! key.to_sym => value
end
end
end
module_function :symbolize
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/persistence.rb | Ruby | mit | 88 | master | 858 | module Chassis
module Persistence
module ClassMethods
def create(*args, &block)
record = new(*args, &block)
record.save
record
end
def repo
begin
@repo ||= StringUtils.constantize "#{name}Repo"
rescue NameError
fail "#{name}Repo not de... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/serializable.rb | Ruby | mit | 88 | master | 893 | require 'json'
require 'yaml'
module Chassis
module Serializable
module ClassMethods
def from_hash(hash)
new.from_hash(hash)
end
def from_json(json)
from_hash JSON.load(json)
end
def from_yaml(yaml)
from_hash YAML.load(yaml)
end
end
class << ... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/string_utils.rb | Ruby | mit | 88 | master | 1,431 | module Chassis
module StringUtils
def demodulize(path)
path = path.to_s
if i = path.rindex('::')
path[(i+2)..-1]
else
path
end
end
module_function :demodulize
def underscore(camel_cased_word)
word = camel_cased_word.to_s.gsub('::', '/')
word.gsub!(/... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/web_service.rb | Ruby | mit | 88 | master | 1,291 | require 'sinatra'
require 'sinatra/json'
require 'rack/contrib/bounce_favicon'
require 'rack/deflater'
module Chassis
class WebService < Sinatra::Base
ParameterMissingError = Chassis.error do |key|
%Q{Request did not provide "#{key}"}
end
helpers do
def extract!(key)
value = params.f... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/form.rb | Ruby | mit | 88 | master | 1,134 | module Chassis
UnknownFormFieldError = Chassis.error do |field|
"#{field} given but not allowed."
end
class FormModule < Module
module InstanceMethods
def initialize(hash = {})
assert_valid_keys! HashUtils.symbolize(hash)
super
yield self if block_given?
end
de... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/faraday.rb | Ruby | mit | 88 | master | 6,547 | module Chassis
class HttpRequestFailedError < StandardError
def initialize(env)
@env = env
end
def to_s
"#{status} - #{description} : #{method} #{url}"
end
def method
env.fetch(:method).upcase
end
def body
env.fetch :body
end
def url
env.fetch(:url... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/observable.rb | Ruby | mit | 88 | master | 387 | module Chassis
module Observable
def add_observer(observer)
@observers ||= []
@observers << observer
end
private
def notify_observers(event, *args)
return unless defined? @observers
@observers.each do |observer|
if observer.respond_to? event
observer.send ev... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/registry.rb | Ruby | mit | 88 | master | 414 | module Chassis
UnregisteredError = Chassis.error do |key|
"#{key.inspect} is not registered!"
end
class Registry
def initialize
@map = { }
end
def []=(key, value)
map[key] = value
end
def fetch(key)
map.fetch key do
fail UnregisteredError, key
end
end... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/delegate.rb | Ruby | mit | 88 | master | 693 | module Chassis
DelegationError = Chassis.error do |method, delegate|
"Cannot delegate #{method} without #{delegate}"
end
class Delegation < Module
def initialize(*methods)
options = methods.last.is_a?(Hash) ? methods.pop : { }
delegate = options.fetch :to do
fail ArgumentError, ":to ... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/circuit_panel.rb | Ruby | mit | 88 | master | 420 | module Chassis
class CircuitPanel
class << self
def build(&block)
raise ArgumentError, "block required" unless block
Class.new self, &block
end
def circuit(name, options = {})
define_method name do
Breaker.circuit name, options
end
end
end
e... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/repo/base_repo.rb | Ruby | mit | 88 | master | 1,779 | module Chassis
class BaseRepo
def create(record)
record.id ||= next_id
map.set record
end
def update(record)
map.set record
end
def delete(record)
map.delete record
end
def clear
map.clear
end
def all(klass)
map.all klass
end
def fin... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/repo/redis_repo.rb | Ruby | mit | 88 | master | 860 | module Chassis
class RedisRepo < Chassis::BaseRepo
class RedisMap
def initialize(redis)
@redis = redis
end
def clear
redis.del key
end
def all(klass)
read.all klass
end
def get(klass, id)
read.get klass, id
end
def set(recor... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/repo/null_repo.rb | Ruby | mit | 88 | master | 580 | module Chassis
class NullRepo
def initialize
@counter = 0
end
def create(record)
@counter = @counter + 1
record.id ||= @counter
end
def update(*)
end
def delete(*)
end
def find(*)
end
def first(*)
end
def last(*)
end
def sample(... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/repo/pstore_repo.rb | Ruby | mit | 88 | master | 955 | module Chassis
class PStoreRepo < BaseRepo
class AccessProxy < Chassis::Proxy
def map
__getobj__[:map] ||= Chassis::Repo::RecordMap.new
end
end
class PStoreMap
def initialize(pstore)
@pstore = AccessProxy.new pstore
end
def clear
pstore.transaction d... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/repo/lazy_association.rb | Ruby | mit | 88 | master | 928 | module Chassis
class Repo
class LazyAssociation < Proxy
def initialize(repo, id)
@repo, @id = repo, id
end
def id
@id
end
def class
@repo.object_class
end
def repo
@repo
end
def instance_of?(klass)
self.class == klas... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/repo/delegation.rb | Ruby | mit | 88 | master | 1,549 | module Chassis
UnknownObjectClassError = Chassis.error do
"Rename class to end in Repo or define object_class"
end
class Repo
module Delegation
def all
backend.all object_class
end
def each(&block)
backend.each object_class, &block
end
def count
bac... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/repo/record_map.rb | Ruby | mit | 88 | master | 713 | module Chassis
class Repo
class RecordMap
def initialize
@hash = { }
end
def set(record)
record_map(record)[record.id] = record
end
def get(klass, id)
class_map(klass).fetch id do
fail RecordNotFoundError.new(klass, id)
end
end
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/core_ext/string.rb | Ruby | mit | 88 | master | 213 | class String
def constantize
Chassis::StringUtils.constantize self
end
def demodulize
Chassis::StringUtils.demodulize self
end
def underscore
Chassis::StringUtils.underscore self
end
end |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/rack/json_body_parser.rb | Ruby | mit | 88 | master | 579 | module Chassis
module Rack
class JsonBodyParser < ::Rack::PostBodyContentTypeParser
def call(env)
begin
if ::Rack::Request.new(env).media_type == APPLICATION_JSON && !(body = env[POST_BODY].read.strip).empty?
env[POST_BODY].rewind # somebody might try to read this stream
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/rack/bouncer.rb | Ruby | mit | 88 | master | 592 | module Chassis
module Rack
class Bouncer
BOUNCERS = [
lambda { |req| ; req.user_agent =~ /masscan/ }
]
def initialize(app, &bouncer)
@app, @bouncer = app, bouncer
end
def call(env)
if bounce?(env)
[403, { }, [ ]]
else
@app.call en... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/rack/instrumentation.rb | Ruby | mit | 88 | master | 381 | require 'rack/runtime'
module Chassis
module Rack
class Instrumentation
def initialize(app, namespace = nil)
stack = ::Rack::Builder.new
stack.use ::Rack::Runtime
stack.use ::Harness::RackInstrumenter, namespace
stack.run app
@app = stack.to_app
end
def... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/rack/no_robots.rb | Ruby | mit | 88 | master | 379 | module Chassis
module Rack
class NoRobots
def initialize(app)
@app = app
end
def call(env)
if env['PATH_INFO'] == '/robots.txt'
[200, {'Content-Type' => 'text/plain'}, [robots_txt]]
else
@app.call env
end
end
def robots_txt
<<-txt... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/rack/health_check.rb | Ruby | mit | 88 | master | 1,007 | module Chassis
HealthCheckError = Class.new RuntimeError
module Rack
class Ping
def initialize(app, &block)
@app, @block = app, block
end
def call(env)
if '/ping' == env.fetch('PATH_INFO')
if @block
begin
result = @block.call(::Rack::Reques... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | lib/chassis/rack/exception_handling.rb | Ruby | mit | 88 | master | 503 | module Chassis
module Rack
class ExceptionHandling
def initialize(app)
@app = app
end
def call(env)
begin
@app.call env
rescue => ex
env['rack.errors'].write "#{ex.class}: #{ex.to_s}\n"
env['rack.errors'].write ex.backtrace.join("\n")
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/hash_utils_test.rb | Ruby | mit | 88 | master | 438 | require_relative 'test_helper'
class HashUtilsTest < MiniTest::Unit::TestCase
def utils
Chassis::HashUtils
end
def test_symbolize_keys_converts_keys_to_symbols
result = utils.symbolize({ 'foo' => 'bar' })
assert_equal({ foo: 'bar'}, result)
end
def test_symbolize_keys_recursises_into_objects
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/string_utils_test.rb | Ruby | mit | 88 | master | 433 | require_relative 'test_helper'
class StringUtilsTest < MiniTest::Unit::TestCase
def utils
Chassis::StringUtils
end
def test_underscore
result = utils.underscore 'FooBar'
assert_equal 'foo_bar', result
end
def test_demodulize
result = utils.demodulize 'Foo::Bar::Baz'
assert_equal 'Baz', ... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/delegate_test.rb | Ruby | mit | 88 | master | 802 | require_relative 'test_helper'
class DelegateTest < MiniTest::Unit::TestCase
class Delegator
include Chassis.delegate(:add, to: :object)
attr_reader :object
def initialize(object)
@object = object
end
end
def test_methods_are_delegated
delegate = Class.new do
def add(number)
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/circuit_panel_test.rb | Ruby | mit | 88 | master | 546 | require_relative 'test_helper'
class CircuitPanelTest < MiniTest::Unit::TestCase
def test_circuit_method_returns_the_given_circuit
panel = Chassis.circuit_panel do
circuit :test, timeout: 10
end.new
circuit = panel.test
assert_kind_of Breaker::Circuit, circuit
assert_equal :test, circuit.n... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/faraday_test.rb | Ruby | mit | 88 | master | 17,120 | require_relative "test_helper"
class FaradayTest < MiniTest::Unit::TestCase
def setup
Harness.config.queue = Harness::SyncQueue.new
Harness.config.collector = Harness::FakeCollector.new
end
def stats
Harness.config.collector
end
def build(url = nil, options = {}, &block)
Faraday.new url, op... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/array_utils_test.rb | Ruby | mit | 88 | master | 529 | require_relative 'test_helper'
class ArrayUtilsTest < MiniTest::Unit::TestCase
def utils
Chassis::ArrayUtils
end
def test_extract_options_removes_options_hash_if_present
args = ['foo', { bar: 'baz' }]
options = utils.extract_options! args
assert_equal({ bar: 'baz' }, options)
assert_equal(%... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/dirty_session_test.rb | Ruby | mit | 88 | master | 3,498 | require_relative 'test_helper'
class DirtySessionTest < MiniTest::Unit::TestCase
class Person
include Chassis::Initializable
attr_accessor :name, :email, :id
end
attr_reader :person
def setup
@person = Person.new do |person|
person.name = 'adam'
person.email = 'example@example.com'
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/web_service_test.rb | Ruby | mit | 88 | master | 2,281 | require_relative 'test_helper'
class WebServiceTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
attr_reader :app
def setup
@app = Chassis::WebService
end
def test_form_errors_return_400
@app = Class.new Chassis::WebService do
get '/' do
raise Chassis::UnknownFormFieldError... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/repo_test.rb | Ruby | mit | 88 | master | 1,763 | require_relative 'test_helper'
class RepoTest < MiniTest::Unit::TestCase
class TestAdapter < Chassis::MemoryRepo
def query_test_empty_array_query(klass, q)
[ ]
end
def query_test_nil_query(klass, q)
nil
end
def query_person_by_name(klass, q)
all(klass).find do |record|
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/serializable_test.rb | Ruby | mit | 88 | master | 1,752 | require_relative 'test_helper'
class SerializationTest < MiniTest::Unit::TestCase
class Post
include Chassis::Serializable
attr_accessor :title
def initialize(hash = {})
hash.each do |key, value|
send "#{key}=", value
end
end
def marshal_dump
{ title: title }
end
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/logger_test.rb | Ruby | mit | 88 | master | 939 | require_relative 'test_helper'
class LoggerTest < MiniTest::Unit::TestCase
def test_log_level_defaults_to_env_variable
with_env :warn do
logger = Chassis::Logger.new $stdout
assert_equal Logger::WARN, logger.level
end
end
def test_log_deafults_debug_without_env_variable
refute ENV['LOG_L... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/error_test.rb | Ruby | mit | 88 | master | 248 | require_relative 'test_helper'
class ErrorTest < MiniTest::Unit::TestCase
def test_delegates_to_tnt
klass = Chassis.error do |foo|
"#{foo} bar"
end
error = klass.new "Adam"
assert_equal "Adam bar", error.message
end
end |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/observable_test.rb | Ruby | mit | 88 | master | 493 | require_relative 'test_helper'
class ObservableTest < MiniTest::Unit::TestCase
class Ship
include Chassis::Observable
def sink!(command)
notify_observers :sink, command
end
end
class Watchtower
def sink(ship, command)
end
end
def test_includes_the_object_in_notifications
shi... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/persistence_test.rb | Ruby | mit | 88 | master | 2,063 | require_relative "test_helper"
class PersistenceTest < MiniTest::Unit::TestCase
class FakeRepo
end
class Model
include Chassis::Persistence
class << self
def repo
FakeRepo
end
end
end
def test_models_can_be_initialize_with_a_hash
assert_includes Model.ancestors, Chassi... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/form_test.rb | Ruby | mit | 88 | master | 608 | require_relative 'test_helper'
class FormTest < MiniTest::Unit::TestCase
class Form
include Chassis.form
attribute :name, String
attribute :email, String
end
def test_initializer_takes_a_block
form = Form.new do |f|
f.name = 'Adam'
end
assert_equal 'Adam', form.name
end
def ... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/registry_test.rb | Ruby | mit | 88 | master | 652 | require_relative 'test_helper'
class RegistryTest < MiniTest::Unit::TestCase
def test_can_get_and_set_values
registry = Chassis::Registry.new
registry[:foo] = 'bar'
assert_equal registry.fetch(:foo), 'bar'
end
def test_fails_with_an_error_if_nothing_registred
registry = Chassis::Registry.new
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/rack/no_robots_test.rb | Ruby | mit | 88 | master | 693 | require_relative '../test_helper'
class NoRobotsTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
class HelloWorld
def call(env)
[200, {'Content-Type' => 'text/plain' }, 'Hi']
end
end
attr_reader :log, :app
def setup
@log = StringIO.new
builder = Rack::Builder.new
build... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/rack/builder_patch_test.rb | Ruby | mit | 88 | master | 742 | require_relative '../test_helper'
class RackBuilderPatchTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
class OrderPrinter
def call(env)
[200, {'Content-Type' => 'text/plain'}, [ env['order'].join(',') ]]
end
end
class OrderedMiddleware
def initialize(app, position)
@app, ... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/rack/exception_handling_test.rb | Ruby | mit | 88 | master | 1,440 | require_relative '../test_helper'
class ExceptionHandlingTest < MiniTest::Unit::TestCase
DummyError = Class.new StandardError
class FakeLogger
def initialize
@written = [ ]
end
def write(*args)
@written << args.join
end
def flush(*args)
@printed = @written
end
def ... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/rack/health_check_test.rb | Ruby | mit | 88 | master | 730 | require_relative '../test_helper'
class HealthCheckTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
class HelloWorld
def call(env)
[200, {'Content-Type' => 'text/plain' }, 'Hi']
end
end
attr_reader :log, :app
def setup
@log = StringIO.new
builder = Rack::Builder.new
bu... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/rack/bouncer_test.rb | Ruby | mit | 88 | master | 920 | require_relative '../test_helper'
class RackBouncer < MiniTest::Unit::TestCase
include Rack::Test::Methods
class HelloWorld
def call(env)
[200, {'Content-Type' => 'text/plain' }, 'Hi']
end
end
attr_reader :app
def setup
builder = Rack::Builder.new
builder.use Chassis::Rack::Bouncer
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/rack/json_body_parser_test.rb | Ruby | mit | 88 | master | 1,161 | require_relative '../test_helper'
class JsonBodyParserTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
class EchoServer
def call(env)
request = Rack::Request.new env
[200, {'Content-Type' => 'text/plain'}, [JSON.dump(request.params)]]
end
end
attr_reader :app
def setup
@... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/rack/instrumentation_test.rb | Ruby | mit | 88 | master | 830 | require_relative '../test_helper'
class RackInstrumentationTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
class HelloWorld
def call(env)
[200, {'Content-Type' => 'text/plain' }, 'Hi']
end
end
attr_reader :app
def setup
Harness.config.collector = Harness::FakeCollector.new
... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/repo/repo_tests.rb | Ruby | mit | 88 | master | 2,848 | module RepoTests
Person = Struct.new :name do
attr_accessor :id
end
PersonNamed = Struct.new :name
PersonFooBarBaz = Class.new
def repo
fail "test class must assign @repo" unless @repo
@repo
end
def setup
repo.clear
repo.initialize_storage
end
def test_crud_operations
asser... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/repo/delegation_test.rb | Ruby | mit | 88 | master | 2,234 | require_relative '../test_helper'
class RepoDelegationTest < MiniTest::Unit::TestCase
class PersonRepo
extend Chassis::Repo::Delegation
def self.obj_class
Person
end
end
class SomethingSomething
extend Chassis::Repo::Delegation
end
Person = Struct.new :name
attr_reader :target, :p... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/repo/null_repo_test.rb | Ruby | mit | 88 | master | 1,325 | require_relative '../test_helper'
class NullRepoTest < MiniTest::Unit::TestCase
Person = Struct.new :name do
attr_accessor :id
end
attr_reader :repo
def setup
@repo = Chassis::NullRepo.new
end
def test_create_sets_the_id
person = Person.new 'ahawkins'
repo.create person
assert perso... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/repo/pstore_repo_test.rb | Ruby | mit | 88 | master | 618 | require_relative '../test_helper'
require_relative 'repo_tests'
require 'pstore'
require 'tempfile'
class PStoreRepoTest < MiniTest::Unit::TestCase
class TestRepo < Chassis::PStoreRepo
def query_person_named(klass, selector)
all(klass).select do |person|
person.name == selector.name
end
e... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/repo/memory_repo_test.rb | Ruby | mit | 88 | master | 514 | require_relative '../test_helper'
require_relative 'repo_tests'
class MemoryRepoTest < MiniTest::Unit::TestCase
class TestRepo < Chassis::MemoryRepo
def query_person_named(klass, selector)
all(klass).select do |person|
person.name == selector.name
end
end
def graph_query_person_named... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/repo/redis_repo_test.rb | Ruby | mit | 88 | master | 538 | require_relative '../test_helper'
require_relative 'repo_tests'
require 'redis'
class RedisRepoTest < MiniTest::Unit::TestCase
class TestRepo < Chassis::RedisRepo
def query_person_named(klass, selector)
all(klass).select do |person|
person.name == selector.name
end
end
def graph_quer... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/repo/lazy_association_test.rb | Ruby | mit | 88 | master | 2,478 | require_relative '../test_helper'
class LazyAssociationTest < MiniTest::Unit::TestCase
class Person
attr_reader :id, :name
def initialize(id, name = nil)
@id, @name = id, name
end
def ==(other)
other.instance_of?(self.class) && other.id == id
end
end
class PersonRepo
class ... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/core_ext/string_test.rb | Ruby | mit | 88 | master | 364 | require_relative '../test_helper'
require 'chassis/core_ext/string'
class StringCoreExtTest < MiniTest::Unit::TestCase
def test_underscore
assert_equal('foo_bar', 'FooBar'.underscore)
end
def test_demodulize
assert_equal('Bar', 'Foo::Bar'.demodulize)
end
def test_constantize
assert_equal self.c... |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | test/core_ext/hash_test.rb | Ruby | mit | 88 | master | 210 | require_relative '../test_helper'
require 'chassis/core_ext/hash'
class HashCoreExtTest < MiniTest::Unit::TestCase
def test_symbolize
assert_equal({ foo: 'bar' }, { 'foo' => 'bar' }.symbolize)
end
end |
github | ahawkins/chassis | https://github.com/ahawkins/chassis | examples/repo.rb | Ruby | mit | 88 | master | 676 | require 'chassis'
class Post
attr_accessor :id, :title, :text
end
repo = Chassis::Repo.default
puts repo.empty? Post #=> true
post = Post.new
post.title = 'Such Repos'
post.text = 'Very wow. Much design.'
repo.save post
puts post.id #=> 1
found_post = repo.find Post, post.id
found_post == post #=> true (no dif... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | Rakefile | Ruby | mit | 88 | main | 319 | require File.expand_path("../spec/example_app/config/application", __FILE__)
Bundler::GemHelper.install_tasks
Rails.application.load_tasks
task(:default).clear
task default: [:spec]
if defined? RSpec
task(:spec).clear
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
end
end
task default: :spec |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | Gemfile | Ruby | mit | 88 | main | 645 | source "https://rubygems.org"
# Specify your gem"s dependencies in yuri-ita.gemspec
gemspec
ruby "3.3.5"
gem "rails"
gem "bootsnap", ">= 1.4.4", require: false
gem "bourbon"
gem "jsbundling-rails"
gem "pg", ">= 0.18", "< 2.0"
gem "puma", "~> 6.6"
gem "redcarpet"
gem "sass-rails", ">= 6"
gem "themoviedb-api"
group ... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | yuri-ita.gemspec | Ruby | mit | 88 | main | 1,450 | lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "yuriita/version"
Gem::Specification.new do |spec|
spec.name = "yuri-ita"
spec.version = Yuriita::VERSION
spec.authors = ["Louis Antonopoulos", "Sally Hall", "Eebs Kobeissi"]
spec.email = ["louis@thoughtbot.c... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/spec_helper.rb | Ruby | mit | 88 | main | 431 | require "bundler/setup"
require "yuriita"
require "support/tokens"
require "support/matchers/produce_tokens"
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/factories.rb | Ruby | mit | 88 | main | 2,600 | FactoryBot.define do
factory :post do
title { "A title" }
body { "A body" }
author
trait :published do
published { true }
end
trait :draft do
published { false }
end
end
factory :category do
name { "Ruby" }
end
factory :author, class: "User" do
username { "u... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/rails_helper.rb | Ruby | mit | 88 | main | 451 | ENV["RAILS_ENV"] = "test"
require File.expand_path("../../spec/example_app/config/environment", __FILE__)
require "rspec/rails"
require "capybara/rails"
require "capybara/rspec"
require "pry"
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each do |path|
require path
end
RSpec.configure do |config|
config... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/yuriita_spec.rb | Ruby | mit | 88 | main | 1,202 | RSpec.describe Yuriita do
it "has a version number" do
expect(Yuriita::VERSION).not_to be nil
end
describe ".filter" do
it "returns an error result when the input could not be parsed" do
relation = double(:relation)
definition = double(:definition)
result = Yuriita.filter(relation, "in... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/app/controllers/documentation_controller.rb | Ruby | mit | 88 | main | 769 | class DocumentationController < ApplicationController
def index
render_documentation_page "README"
end
def show
render_documentation_page "docs/#{params[:page]}"
end
private
def render_documentation_page(name)
path = full_page_path(name)
if File.exist?(path)
html = File.read(path)
... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/app/controllers/movies_controller.rb | Ruby | mit | 88 | main | 362 | class MoviesController < ApplicationController
def index
table = build_table
render locals: {table:}
end
private
def build_table
Yuriita::Table.new(
relation: Movie.all,
params: table_params,
configuration: MovieDefinition.build,
param_key: :query
)
end
def table_p... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/app/models/movie_definition.rb | Ruby | mit | 88 | main | 3,950 | class MovieDefinition
def self.build
new.build
end
def build
Yuriita::Configuration.new(definitions)
end
private
def definitions
{
status: status_definition,
adult: adult_definition,
sort: sort_definition,
movie: movie_scope
}
end
def movie_scope
Yuriita::... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/app/models/genre_sync.rb | Ruby | mit | 88 | main | 337 | class GenreSync
def self.run(client:)
new(client:).run
end
def initialize(client:)
@client = client
end
def run
insert_or_update_genres
end
private
attr_reader :client
def insert_or_update_genres
Genre.upsert_all(genre_data, unique_by: :tmdb_id)
end
def genre_data
client.... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/app/models/tmdb_client.rb | Ruby | mit | 88 | main | 1,777 | class TmdbClient
def initialize
Tmdb::Api.key(ENV["TMDB_API_KEY"])
end
def top_rated
data.map do |movie_data|
{
tmdb_id: movie_data.id,
title: movie_data.title,
original_title: movie_data.original_title,
tagline: movie_data.tagline,
overview: movie_data.overv... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/app/models/post_definition.rb | Ruby | mit | 88 | main | 3,544 | class PostDefinition
def self.build
new.build
end
def build
Yuriita::Configuration.new(definitions)
end
private
def definitions
{
published: published_definition,
category: category_definition,
sort: sort_definition,
post: post_scope,
author: author_definition
... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/app/models/movie_sync.rb | Ruby | mit | 88 | main | 595 | class MovieSync
def self.run(client:)
new(client:).run
end
def initialize(client:)
@client = client
end
def run
insert_or_update_movies
insert_or_update_movie_genres
end
private
attr_reader :client
def insert_or_update_movies
Movie.upsert_all(movie_data, unique_by: :tmdb_id)
... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/app/models/post.rb | Ruby | mit | 88 | main | 533 | class Post < ApplicationRecord
has_many :post_categories
has_many :categories, through: :post_categories
belongs_to :author, class_name: "User"
validates_presence_of :title, :body
scope :published, -> { where(published: true) }
scope :draft, -> { where(published: false) }
def self.authored_by(username)... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/app/models/movie.rb | Ruby | mit | 88 | main | 689 | class Movie < ApplicationRecord
has_many :movie_genres, dependent: :destroy
has_many :genres, through: :movie_genres
module Status
RUMORED = "Rumored".freeze
POST_PRODUCTION = "Post Production".freeze
RELEASED = "Released".freeze
CANCELLED = "Cancelled".freeze
end
scope :rumored, -> { where(... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/db/schema.rb | Ruby | mit | 88 | main | 3,495 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/db/migrate/20200327150540_create_movie_genres.rb | Ruby | mit | 88 | main | 327 | class CreateMovieGenres < ActiveRecord::Migration[6.0]
def change
create_table :movie_genres do |t|
t.references :movie, null: false, foreign_key: true
t.references :genre, null: false, foreign_key: true
t.timestamps
end
add_index :movie_genres, [:movie_id, :genre_id], unique: true
e... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/db/migrate/20200313180126_change_movie_revenue_limit.rb | Ruby | mit | 88 | main | 210 | class ChangeMovieRevenueLimit < ActiveRecord::Migration[6.0]
def up
change_column :movies, :revenue, :integer, limit: 8
end
def down
change_column :movies, :revenue, :integer, limit: 4
end
end |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/db/migrate/20200311125252_create_movies.rb | Ruby | mit | 88 | main | 525 | class CreateMovies < ActiveRecord::Migration[6.0]
def change
create_table :movies do |t|
t.integer :tmdb_id, null: false, index: {unique: true}
t.string :title
t.string :original_title
t.string :tagline
t.string :overview
t.boolean :adult
t.string :status
t.integer ... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/db/migrate/20200214200848_create_posts.rb | Ruby | mit | 88 | main | 256 | class CreatePosts < ActiveRecord::Migration[6.0]
def change
create_table :posts do |t|
t.string :title, null: false
t.string :body, null: false
t.boolean :published, default: false, null: false
t.timestamps
end
end
end |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/db/migrate/20200327150102_create_genres.rb | Ruby | mit | 88 | main | 215 | class CreateGenres < ActiveRecord::Migration[6.0]
def change
create_table :genres do |t|
t.integer :tmdb_id, null: false, index: {unique: true}
t.string :name
t.timestamps
end
end
end |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/db/migrate/20200223143509_create_post_categories.rb | Ruby | mit | 88 | main | 268 | class CreatePostCategories < ActiveRecord::Migration[6.0]
def change
create_table :post_categories do |t|
t.references :post, null: false, foreign_key: true
t.references :category, null: false, foreign_key: true
t.timestamps
end
end
end |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/config/puma.rb | Ruby | mit | 88 | main | 1,667 | # This configuration file will be evaluated by Puma. The top-level methods that
# are invoked here are part of Puma's configuration DSL. For more information
# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
# Puma starts a configurable number of processes (workers) and each process
# serves... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/config/application.rb | Ruby | mit | 88 | main | 1,465 | require_relative "boot"
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
# require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
# require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "acti... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/config/boot.rb | Ruby | mit | 88 | main | 213 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
require "bundler/setup" # Set up gems listed in the Gemfile.
require "bootsnap/setup" # Speed up boot time by caching expensive operations. |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/config/environments/test.rb | Ruby | mit | 88 | main | 2,319 | require "active_support/core_ext/integer/time"
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data the... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/config/environments/development.rb | Ruby | mit | 88 | main | 2,391 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded any time
# it changes. This slows down response time but is perfect for developme... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/example_app/config/environments/production.rb | Ruby | mit | 88 | main | 3,601 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.enable_reloading = false
# Eager load code on boot. This eager loads most of Rails and
# your app... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/support/capybara.rb | Ruby | mit | 88 | main | 411 | RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end
config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome_headless
end
config.before(:each, js: true) do
Capybara.page.driver.browser.manage.window.resize_to(1920, 1080)
end
config.... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/support/tokens.rb | Ruby | mit | 88 | main | 312 | module Tokens
def tokens(*tokens)
tokens.map.with_index do |token, i|
type, value = token
length = (value || "").length
pos = RLTK::StreamPosition.new(i, 1, i, length, nil)
RLTK::Token.new(type, value, pos)
end
end
end
RSpec.configure do |config|
config.include Tokens
end |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/models/movie_spec.rb | Ruby | mit | 88 | main | 1,421 | require "rails_helper"
RSpec.describe Movie, type: :model do
describe ".rumored" do
it "returns movies with the rumored status" do
rumored = create(:movie, :rumored)
create(:movie, :post_production)
results = Movie.rumored
expect(results).to contain_exactly(rumored)
end
end
des... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/models/movie_sync_spec.rb | Ruby | mit | 88 | main | 700 | require "rails_helper"
RSpec.describe MovieSync do
describe "#run" do
it "fetches the top 100 movies from TMDB and inserts them into the DB" do
fight_club = attributes_for(
:movie,
title: "Fight Club",
created_at: Time.now,
updated_at: Time.now
)
the_prestige = ... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/models/user_spec.rb | Ruby | mit | 88 | main | 227 | require "rails_helper"
RSpec.describe User, type: :model do
describe "username" do
it "is required" do
user = User.new
user.valid?
expect(user.errors).to be_added(:username, :blank)
end
end
end |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/models/post_spec.rb | Ruby | mit | 88 | main | 800 | require "rails_helper"
RSpec.describe Post, type: :model do
describe ".published" do
it "returns published posts" do
published = create(:post, :published)
create(:post, :draft)
results = Post.published
expect(results).to contain_exactly(published)
end
end
describe ".draft" do
... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/models/genre_sync_spec.rb | Ruby | mit | 88 | main | 620 | require "rails_helper"
RSpec.describe GenreSync do
describe "#run" do
it "fetches all genres from TMDB and inserts them into the DB" do
comedy = attributes_for(
:genre,
name: "Comedy",
created_at: Time.now,
updated_at: Time.now
)
drama = attributes_for(
:... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/system/movies_spec.rb | Ruby | mit | 88 | main | 1,666 | require "rails_helper"
RSpec.describe "user views the movies page" do
scenario "views a list of movies" do
create(:movie, title: "Fight Club")
create(:movie, title: "The Prestige")
create(:movie, title: "Pretty Woman")
visit movies_path
expect(page).to have_content("Fight Club")
expect(page... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/system/documentation_spec.rb | Ruby | mit | 88 | main | 242 | require "rails_helper"
RSpec.describe "viewing documentation" do
it "shows the readme on the root page" do
visit root_path
expect(page).to have_content "What is Yuri-ita?"
expect(page).to have_content "Installation"
end
end |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/integration/empty_spec.rb | Ruby | mit | 88 | main | 288 | require "rails_helper"
RSpec.describe "an empty input string" do
it "results in the original relation" do
create_list(:post, 3)
result = Yuriita.filter(
Post.all,
"",
PostDefinition.build
)
expect(result.relation).to match_array(Post.all)
end
end |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/integration/combined_search_filter_sort_spec.rb | Ruby | mit | 88 | main | 636 | require "rails_helper"
RSpec.describe "combining expressions, search, and sort" do
it "returns keyword results, expression results, and sorted results" do
create(:post, title: "Cats are great", published: false)
elephant_post = create(:post, title: "Elephants are great", published: true)
duck_post = crea... |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/integration/sorting_spec.rb | Ruby | mit | 88 | main | 315 | require "rails_helper"
RSpec.describe "sorting" do
it "sorts results" do
create(:post, title: "Cats are great")
create(:post, title: "Whoa. Elephants.")
create(:post, title: "Ducks are okay too")
Yuriita.filter(
Post.all,
"sort:title-asc",
PostDefinition.build
)
end
end |
github | thoughtbot/yuri-ita | https://github.com/thoughtbot/yuri-ita | spec/integration/filtering/by_expression_spec.rb | Ruby | mit | 88 | main | 939 | require "rails_helper"
RSpec.describe "filtering by expression" do
it "returns results matching an expression" do
published = create(:post, published: true)
create(:post, published: false)
result = Yuriita.filter(
Post.all,
"is:published",
PostDefinition.build
)
expect(result.... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.