Skip to content

Instantly share code, notes, and snippets.

@jamesmoriarty
Created May 28, 2017 11:33
Show Gist options
  • Save jamesmoriarty/9d7b7345df29b33b276eb326be17a0fe to your computer and use it in GitHub Desktop.
Save jamesmoriarty/9d7b7345df29b33b276eb326be17a0fe to your computer and use it in GitHub Desktop.
require "minitest/autorun"
class Proxy
module DSL
module ClassMethods
def option(name)
define_method(name) do |value|
tap do
options[name] = value
end
end
end
end
def self.included(base)
base.extend(ClassMethods)
end
def options
@__options ||= {}
end
end
include DSL
option :per_page
option :page
end
describe Proxy::DSL do
before do
@proxy = Proxy.new
end
it "#page" do
@proxy.page(2).options.must_equal(page: 2)
@proxy.page(2).per_page(25).options.must_equal(page: 2, per_page: 25)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment