Class: MemoryModel::Base::Fields::Field
- Inherits:
-
Object
- Object
- MemoryModel::Base::Fields::Field
- Defined in:
- lib/memory_model/base/fields/field.rb,
lib/memory_model/base/auto_increment.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #==(other_object) ⇒ Object
- #comparable? ⇒ Boolean
- #default ⇒ Object
- #increment! ⇒ Object
-
#initialize(name, options = {}) ⇒ Field
constructor
A new instance of Field.
- #readonly? ⇒ Boolean
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Field
Returns a new instance of Field.
25 26 27 28 |
# File 'lib/memory_model/base/fields/field.rb', line 25 def initialize(name, ={}) @name = name.to_sym = .reverse_merge!({ readonly: false, comparable: true }) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/memory_model/base/fields/field.rb', line 23 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/memory_model/base/fields/field.rb', line 23 def end |
Instance Method Details
#==(other_object) ⇒ Object
30 31 32 |
# File 'lib/memory_model/base/fields/field.rb', line 30 def ==(other_object) self.to_sym == other_object.to_sym end |
#comparable? ⇒ Boolean
34 35 36 |
# File 'lib/memory_model/base/fields/field.rb', line 34 def comparable? !![:comparable] end |
#default ⇒ Object
38 39 40 |
# File 'lib/memory_model/base/fields/field.rb', line 38 def default [:default] end |
#increment! ⇒ Object
38 39 40 41 42 |
# File 'lib/memory_model/base/auto_increment.rb', line 38 def increment! raise ArguementError, "#{name} is not incrementable" unless [:auto_increment] === true @incrementor ||= 0 @incrementor += 1 end |
#readonly? ⇒ Boolean
42 43 44 |
# File 'lib/memory_model/base/fields/field.rb', line 42 def readonly? !![:readonly] end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/memory_model/base/fields/field.rb', line 50 def to_s @name.to_s end |
#to_sym ⇒ Object
46 47 48 |
# File 'lib/memory_model/base/fields/field.rb', line 46 def to_sym @name.to_sym end |