Class: Degu::Renum::EnumeratedValue::Field
- Defined in:
- lib/degu/renum/enumerated_value.rb
Overview
This class encapsulates an enum field (аctually a method with arity == 0).
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#block? ⇒ Boolean
Returns true if a block was given.
-
#default ⇒ Object
Returns the value of the :default option.
-
#default? ⇒ Boolean
Returns true if the :default option was given.
-
#default_value(obj, options) ⇒ Object
Determine the default value for the enum value
obj
ifoptions
is the options hash given to the init method. -
#inspect ⇒ Object
Returns a detailed string representation of this field.
-
#to_s ⇒ Object
Returns the name as a string.
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
56 57 58 |
# File 'lib/degu/renum/enumerated_value.rb', line 56 def block @block end |
#name ⇒ Object
Returns the value of attribute name
56 57 58 |
# File 'lib/degu/renum/enumerated_value.rb', line 56 def name @name end |
#options ⇒ Object
Returns the value of attribute options
56 57 58 |
# File 'lib/degu/renum/enumerated_value.rb', line 56 def @options end |
Instance Method Details
#block? ⇒ Boolean
Returns true if a block was given.
68 69 70 |
# File 'lib/degu/renum/enumerated_value.rb', line 68 def block? !!block end |
#default ⇒ Object
Returns the value of the :default option.
63 64 65 |
# File 'lib/degu/renum/enumerated_value.rb', line 63 def default [:default] end |
#default? ⇒ Boolean
Returns true if the :default option was given.
58 59 60 |
# File 'lib/degu/renum/enumerated_value.rb', line 58 def default? .key?(:default) end |
#default_value(obj, options) ⇒ Object
Determine the default value for the enum value obj
if options
is the options hash given to the init method.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/degu/renum/enumerated_value.rb', line 74 def default_value(obj, ) field_value = [name] if field_value.nil? if default? default_value = default elsif block? default_value = block[obj] end else field_value end end |
#inspect ⇒ Object
Returns a detailed string representation of this field.
93 94 95 |
# File 'lib/degu/renum/enumerated_value.rb', line 93 def inspect "#<#{self.class}: #{self} #{.inspect}>" end |
#to_s ⇒ Object
Returns the name as a string.
88 89 90 |
# File 'lib/degu/renum/enumerated_value.rb', line 88 def to_s name.to_s end |