Class: Monolens::Lens::Options
- Inherits:
-
Object
- Object
- Monolens::Lens::Options
- Includes:
- FetchSupport
- Defined in:
- lib/monolens/lens/options.rb
Constant Summary collapse
- NO_DEFAULT =
Object.new.freeze
Instance Method Summary collapse
- #fetch(key, default = NO_DEFAULT, on = @options) ⇒ Object
-
#initialize(options, registry, signature) ⇒ Options
constructor
A new instance of Options.
- #lens(arg, registry = @registry) ⇒ Object
- #to_h ⇒ Object
Methods included from FetchSupport
Constructor Details
#initialize(options, registry, signature) ⇒ Options
Returns a new instance of Options.
6 7 8 9 10 11 12 13 14 |
# File 'lib/monolens/lens/options.rb', line 6 def initialize(, registry, signature) raise ArgumentError if .nil? raise ArgumentError if registry.nil? raise ArgumentError if signature.nil? @signature = signature @registry = compile_macros(, registry) @options = @signature.(, @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_h ⇒ Object
38 39 40 |
# File 'lib/monolens/lens/options.rb', line 38 def to_h @options.dup end |