Class: TransientModel::Fields::BaseField
- Inherits:
-
Object
- Object
- TransientModel::Fields::BaseField
- Defined in:
- lib/transient_model/fields/base_field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#default_value ⇒ any
Return the default value that should be used for the field.
- #getter_method_name ⇒ Object
-
#initialize(name, options = {}) ⇒ BaseField
constructor
A new instance of BaseField.
-
#instance_variable_name ⇒ Symbol
Return the symbol representation of the instance variable used by the defining model object.
- #setter_method_name ⇒ Object
-
#type ⇒ any
Return the data type for this field.
Constructor Details
#initialize(name, options = {}) ⇒ BaseField
Returns a new instance of BaseField.
15 16 17 18 19 20 21 22 |
# File 'lib/transient_model/fields/base_field.rb', line 15 def initialize(name, = {}) defaults = { type: String } @name = name = defaults.merge end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/transient_model/fields/base_field.rb', line 6 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/transient_model/fields/base_field.rb', line 6 def end |
Instance Method Details
#default_value ⇒ any
Return the default value that should be used for the field.
29 30 31 |
# File 'lib/transient_model/fields/base_field.rb', line 29 def default_value .fetch(:default, nil) end |
#getter_method_name ⇒ Object
52 53 54 |
# File 'lib/transient_model/fields/base_field.rb', line 52 def getter_method_name "#{ @name }".to_sym end |
#instance_variable_name ⇒ Symbol
Return the symbol representation of the instance variable used by the defining model object.
48 49 50 |
# File 'lib/transient_model/fields/base_field.rb', line 48 def instance_variable_name "@#{ @name }".to_sym end |
#setter_method_name ⇒ Object
56 57 58 |
# File 'lib/transient_model/fields/base_field.rb', line 56 def setter_method_name "#{ @name }=".to_sym end |
#type ⇒ any
Return the data type for this field.
38 39 40 |
# File 'lib/transient_model/fields/base_field.rb', line 38 def type @type ||= .fetch(:type, String) end |