Class: Wardrobe::Plugins::Validation::Validation

Inherits:
Hash
  • Object
show all
Defined in:
lib/wardrobe/plugins/validation/validation.rb

Constant Summary collapse

SPECIAL_METHODS =
Set.new([:each?, :each_key?, :each_value?])

Instance Method Summary collapse

Constructor Details

#initialize(method, argument) ⇒ Validation

Returns a new instance of Validation.



6
7
8
9
# File 'lib/wardrobe/plugins/validation/validation.rb', line 6

def initialize(method, argument)
  self[:method] = method
  self[:argument] = argument
end

Instance Method Details

#&(other) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/wardrobe/plugins/validation/validation.rb', line 39

def &(other)
  if method == :_and_
    argument << other
    self
  else
    self.class.new(:_and_, [self, other])
  end
end

#>(other) ⇒ Object



57
58
59
# File 'lib/wardrobe/plugins/validation/validation.rb', line 57

def >(other)
  self.class.new(:_then_, [self, other])
end

#argsObject



19
20
21
22
23
24
25
# File 'lib/wardrobe/plugins/validation/validation.rb', line 19

def args
  @args ||= begin
    arr = [ method ]
    arr << argument if argument
    arr
  end
end

#argumentObject



15
16
17
# File 'lib/wardrobe/plugins/validation/validation.rb', line 15

def argument
  self[:argument]
end

#methodObject



11
12
13
# File 'lib/wardrobe/plugins/validation/validation.rb', line 11

def method
  self[:method]
end

#typeObject



29
30
31
32
33
34
35
36
37
# File 'lib/wardrobe/plugins/validation/validation.rb', line 29

def type
  @type ||= begin
    if method[/^_.+_$/] || SPECIAL_METHODS.include?(method)
      :special
    else
      :value
    end
  end
end

#|(other) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/wardrobe/plugins/validation/validation.rb', line 48

def |(other)
  if method == :_or_
    argument<< other
    self
  else
    self.class.new(:_or_, [self, other])
  end
end