Class: Monolens::Type::Strategy
- Inherits:
-
Object
- Object
- Monolens::Type::Strategy
- Includes:
- ErrorHandling
- Defined in:
- lib/monolens/type/strategy.rb
Class Method Summary collapse
- .error(valid) ⇒ Object
- .missing(valid) ⇒ Object
- .priority(valid) ⇒ Object
- .selection(valid) ⇒ Object
Instance Method Summary collapse
- #===(arg) ⇒ Object
- #dress(arg, registry, &block) ⇒ Object
-
#initialize(kind, valid) ⇒ Strategy
constructor
A new instance of Strategy.
Constructor Details
#initialize(kind, valid) ⇒ Strategy
Returns a new instance of Strategy.
6 7 8 9 |
# File 'lib/monolens/type/strategy.rb', line 6 def initialize(kind, valid) @kind = kind @valid = valid end |
Class Method Details
.error(valid) ⇒ Object
15 16 17 |
# File 'lib/monolens/type/strategy.rb', line 15 def self.error(valid) new('error', valid) end |
.missing(valid) ⇒ Object
19 20 21 |
# File 'lib/monolens/type/strategy.rb', line 19 def self.missing(valid) new('missing', valid) end |
.priority(valid) ⇒ Object
23 24 25 |
# File 'lib/monolens/type/strategy.rb', line 23 def self.priority(valid) new('priority', valid) end |
.selection(valid) ⇒ Object
11 12 13 |
# File 'lib/monolens/type/strategy.rb', line 11 def self.selection(valid) new('selection', valid) end |
Instance Method Details
#===(arg) ⇒ Object
43 44 45 46 47 |
# File 'lib/monolens/type/strategy.rb', line 43 def ===(arg) !!dress(arg, nil) rescue TypeError false end |
#dress(arg, registry, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/monolens/type/strategy.rb', line 27 def dress(arg, registry, &block) case arg when ::Symbol fail!(arg, &block) unless @valid.include?(arg.to_s) arg when ::String fail!(arg, &block) unless @valid.include?(arg) arg.to_sym when ::Array fail!(arg, &block) unless (arg.map(&:to_s) - @valid).empty? arg.map(&:to_sym) else fail!(arg, &block) end end |