Class: Lite::Command::Attribute
- Inherits:
-
Object
- Object
- Lite::Command::Attribute
- Defined in:
- lib/lite/command/attribute.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
TODO: allow procs.
-
#errors ⇒ Object
readonly
TODO: allow procs.
-
#method_name ⇒ Object
readonly
TODO: allow procs.
-
#options ⇒ Object
readonly
TODO: allow procs.
Instance Method Summary collapse
- #filled? ⇒ Boolean
- #from ⇒ Object
-
#initialize(command, 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(command, method_name, options) ⇒ Attribute
Returns a new instance of Attribute.
11 12 13 14 15 16 |
# File 'lib/lite/command/attribute.rb', line 11 def initialize(command, method_name, ) @command = command @method_name = method_name = @errors = [] end |
Instance Attribute Details
#command ⇒ Object (readonly)
TODO: allow procs
9 10 11 |
# File 'lib/lite/command/attribute.rb', line 9 def command @command end |
#errors ⇒ Object (readonly)
TODO: allow procs
9 10 11 |
# File 'lib/lite/command/attribute.rb', line 9 def errors @errors end |
#method_name ⇒ Object (readonly)
TODO: allow procs
9 10 11 |
# File 'lib/lite/command/attribute.rb', line 9 def method_name @method_name end |
#options ⇒ Object (readonly)
TODO: allow procs
9 10 11 |
# File 'lib/lite/command/attribute.rb', line 9 def end |
Instance Method Details
#filled? ⇒ Boolean
22 23 24 |
# File 'lib/lite/command/attribute.rb', line 22 def filled? Utils.call(command, [:filled]) || false end |
#from ⇒ Object
18 19 20 |
# File 'lib/lite/command/attribute.rb', line 18 def from [:from] || :context end |
#required? ⇒ Boolean
26 27 28 |
# File 'lib/lite/command/attribute.rb', line 26 def required? Utils.call(command, [:required]) || false end |
#typed? ⇒ Boolean
30 31 32 |
# File 'lib/lite/command/attribute.rb', line 30 def typed? .key?(:types) && types.any? end |
#types ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lite/command/attribute.rb', line 34 def types @types ||= begin t = Array(Utils.call(command, [:types])) if filled? t - [NilClass] else t | [NilClass] end end end |
#valid? ⇒ Boolean
55 56 57 |
# File 'lib/lite/command/attribute.rb', line 55 def valid? errors.empty? end |
#validate! ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/lite/command/attribute.rb', line 46 def validate! validate_respond_attribute! return unless errors.empty? validate_required_attribute! validate_attribute_type! validate_attribute_filled! end |
#value ⇒ Object
59 60 61 62 63 |
# File 'lib/lite/command/attribute.rb', line 59 def value return @value if defined?(@value) @value = command.send(from).public_send(method_name) end |