Class: Lite::Command::Attribute
- Inherits:
-
Object
- Object
- Lite::Command::Attribute
- Defined in:
- lib/lite/command/attribute.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #filled? ⇒ Boolean
- #from ⇒ Object
-
#initialize(method_name, options) ⇒ Attribute
constructor
A new instance of Attribute.
- #required? ⇒ Boolean
- #typed? ⇒ Boolean
- #types ⇒ Object
- #valid? ⇒ Boolean
- #validate! ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(method_name, options) ⇒ Attribute
Returns a new instance of Attribute.
10 11 12 13 14 |
# File 'lib/lite/command/attribute.rb', line 10 def initialize(method_name, ) @method_name = method_name @options = @errors = [] end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
7 8 9 |
# File 'lib/lite/command/attribute.rb', line 7 def command @command end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/lite/command/attribute.rb', line 8 def errors @errors end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
8 9 10 |
# File 'lib/lite/command/attribute.rb', line 8 def method_name @method_name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/lite/command/attribute.rb', line 8 def @options end |
Instance Method Details
#filled? ⇒ Boolean
20 21 22 |
# File 'lib/lite/command/attribute.rb', line 20 def filled? Utils.call(command, [:filled]) || false end |
#from ⇒ Object
16 17 18 |
# File 'lib/lite/command/attribute.rb', line 16 def from [:from] || :context end |
#required? ⇒ Boolean
24 25 26 |
# File 'lib/lite/command/attribute.rb', line 24 def required? Utils.call(command, [:required]) || false end |
#typed? ⇒ Boolean
28 29 30 |
# File 'lib/lite/command/attribute.rb', line 28 def typed? .key?(:types) && types.any? end |
#types ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lite/command/attribute.rb', line 32 def types @types ||= begin t = Array(Utils.call(command, [:types])) if filled? t.uniq - [NilClass] else t | [NilClass] end end end |
#valid? ⇒ Boolean
53 54 55 |
# File 'lib/lite/command/attribute.rb', line 53 def valid? errors.empty? end |
#validate! ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/lite/command/attribute.rb', line 44 def validate! validate_respond_attribute! return unless errors.empty? validate_required_attribute! validate_attribute_type! validate_attribute_filled! end |
#value ⇒ Object
57 58 59 60 61 |
# File 'lib/lite/command/attribute.rb', line 57 def value return @value if defined?(@value) @value = command.send(from).public_send(method_name) end |