Module: Jetski::Model::Attributes
- Included in:
- Jetski::Model
- Defined in:
- lib/jetski/model/attributes.rb
Instance Method Summary collapse
- #attribute_names ⇒ Object
-
#attributes(*string_attributes, **custom_attributes) ⇒ Object
class method for user to configure add/remove attributes on model.
- #db_attribute_values ⇒ Object
Instance Method Details
#attribute_names ⇒ Object
20 21 22 |
# File 'lib/jetski/model/attributes.rb', line 20 def attribute_names @_attribute_names || [] end |
#attributes(*string_attributes, **custom_attributes) ⇒ Object
class method for user to configure add/remove attributes on model
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/jetski/model/attributes.rb', line 5 def attributes(*string_attributes, **custom_attributes) @_db_string_attributes = string_attributes @_db_custom_attributes = custom_attributes combined_attributes = string_attributes + custom_attributes.map { |k, _v| k } @_attribute_names ||= [] @_attribute_names.concat(combined_attributes) @_attribute_names.concat([:created_at, :updated_at, :id]) # defaults @_attribute_names = @_attribute_names.uniq @_attribute_names.each do |attribute| define_method attribute do @virtual_attributes[attribute] end end end |
#db_attribute_values ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jetski/model/attributes.rb', line 24 def db_attribute_values # Returns the formatted objects with types for each attribute _db_attributes = [] @_db_string_attributes.each do |value| _db_attributes << { name: value, type: :string } end @_db_custom_attributes.each do |key, value| _db_attributes << { name: key, type: value } end _db_attributes end |