Class: Hatch::ValidatedAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/hatch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr, value, error, valid) ⇒ ValidatedAttribute

Returns a new instance of ValidatedAttribute.



108
109
110
# File 'lib/hatch.rb', line 108

def initialize(attr, value, error, valid)
  @attr, @value, @error, @valid = attr, value, error, valid
end

Instance Attribute Details

#attrObject (readonly)

Returns the value of attribute attr.



102
103
104
# File 'lib/hatch.rb', line 102

def attr
  @attr
end

#errorObject (readonly)

Returns the value of attribute error.



102
103
104
# File 'lib/hatch.rb', line 102

def error
  @error
end

#valueObject (readonly)

Returns the value of attribute value.



102
103
104
# File 'lib/hatch.rb', line 102

def value
  @value
end

Class Method Details

.validate(attr, value, error, &block) ⇒ Object



104
105
106
# File 'lib/hatch.rb', line 104

def self.validate(attr, value, error, &block)
  new(attr, value, error, yield(value))
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/hatch.rb', line 116

def invalid?
  !@valid
end

#valid?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/hatch.rb', line 112

def valid?
  @valid
end