Module: Val::DSL
- Included in:
- Val
- Defined in:
- lib/val.rb
Instance Method Summary collapse
- #is(array) ⇒ Object
- #is_a(type) ⇒ Object
- #key(name, *conditions) ⇒ Object
- #m(name) ⇒ Object
- #OR(*all) ⇒ Object
- #val(&block) ⇒ Object
Instance Method Details
#is(array) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/val.rb', line 29 def is array condition = -> value { begin array.to_proc === value rescue TypeError, ArgumentError false end } @conditions << condition end |
#is_a(type) ⇒ Object
24 25 26 27 |
# File 'lib/val.rb', line 24 def is_a type condition = -> value { value.is_a? type } @conditions << condition end |
#key(name, *conditions) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/val.rb', line 11 def key name, *conditions first = conditions.first if [Module, Val, NilClass].any? &[first, :is_a?] type = first @conditions << Key.new(name, type) else @conditions.concat conditions.map { |array| ArrayCondition.new name, array } end end |
#m(name) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/val.rb', line 40 def m name condition = -> value { value.respond_to? name } @conditions << condition end |
#val(&block) ⇒ Object
7 8 9 |
# File 'lib/val.rb', line 7 def val &block self.class.new &block end |