Class: ApiVersions::DSL

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/api-versions/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, &block) ⇒ DSL

Returns a new instance of DSL.



7
8
9
10
11
# File 'lib/api-versions/dsl.rb', line 7

def initialize(context, &block)
  @context = context
  singleton_class.def_delegators :@context, *(@context.public_methods - public_methods)
  instance_eval(&block)
end

Instance Method Details

#cache(options, &block) ⇒ Object



27
28
29
30
31
# File 'lib/api-versions/dsl.rb', line 27

def cache(options, &block)
  @resource_cache ||= {}
  @resource_cache[options[:as]] = block
  yield
end

#inherit(options) ⇒ Object



21
22
23
24
25
# File 'lib/api-versions/dsl.rb', line 21

def inherit(options)
  Array.wrap(options[:from]).each do |block|
     @resource_cache[block].call
  end
end

#version(version_number, &block) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/api-versions/dsl.rb', line 13

def version(version_number, &block)
  VersionCheck.default_version ||= version_number

  constraints VersionCheck.new(version: version_number) do
    scope({ module: "v#{version_number}" }, &block)
  end
end