Class: Lite::Command::AttributeValidator
- Inherits:
-
Object
- Object
- Lite::Command::AttributeValidator
- Defined in:
- lib/lite/command/attribute_validator.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
- #attributes ⇒ Object
- #errors ⇒ Object
-
#initialize(command) ⇒ AttributeValidator
constructor
A new instance of AttributeValidator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(command) ⇒ AttributeValidator
Returns a new instance of AttributeValidator.
9 10 11 |
# File 'lib/lite/command/attribute_validator.rb', line 9 def initialize(command) @command = command end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/lite/command/attribute_validator.rb', line 7 def command @command end |
Instance Method Details
#attributes ⇒ Object
13 14 15 16 17 18 |
# File 'lib/lite/command/attribute_validator.rb', line 13 def attributes @attributes ||= command.class.attributes.map do |_method_name, attribute| attribute.tap { |a| a.command = command } end end |
#errors ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/lite/command/attribute_validator.rb', line 20 def errors @errors ||= attributes.each_with_object({}) do |attribute, h| next if attribute.tap(&:validate!).valid? h[attribute.from] ||= [] h[attribute.from] = h[attribute.from] | attribute.errors end end |
#valid? ⇒ Boolean
29 30 31 |
# File 'lib/lite/command/attribute_validator.rb', line 29 def valid? attributes.empty? || errors.empty? end |