Class: Monolens::Lens::Options

Inherits:
Object
  • Object
show all
Includes:
FetchSupport
Defined in:
lib/monolens/lens/options.rb

Constant Summary collapse

NO_DEFAULT =
Object.new.freeze

Instance Method Summary collapse

Methods included from FetchSupport

#fetch_on

Constructor Details

#initialize(options, registry, signature) ⇒ Options

Returns a new instance of Options.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
# File 'lib/monolens/lens/options.rb', line 6

def initialize(options, registry, signature)
  raise ArgumentError if options.nil?
  raise ArgumentError if registry.nil?
  raise ArgumentError if signature.nil?

  @signature = signature
  @registry =  compile_macros(options, registry)
  @options = @signature.dress_options(options, @registry)
end

Instance Method Details

#fetch(key, default = NO_DEFAULT, on = @options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/monolens/lens/options.rb', line 24

def fetch(key, default = NO_DEFAULT, on = @options)
  if on.key?(key)
    on[key]
  elsif on.key?(s = key.to_s)
    on[s]
  elsif on.key?(sym = key.to_sym)
    on[sym]
  elsif default != NO_DEFAULT
    default
  else
    raise Error, "Missing option #{key}"
  end
end

#lens(arg, registry = @registry) ⇒ Object



20
21
22
# File 'lib/monolens/lens/options.rb', line 20

def lens(arg, registry = @registry)
  registry.lens(arg)
end

#to_hObject



38
39
40
# File 'lib/monolens/lens/options.rb', line 38

def to_h
  @options.dup
end