Module: NinjaModel::AttributeMethods::ClassMethods
- Defined in:
- lib/ninja_model/attribute_methods.rb
Instance Method Summary collapse
- #attribute(name, data_type, *args) ⇒ Object
- #attribute_names ⇒ Object (also: #column_names)
- #columns ⇒ Object
- #model_attributes_hash ⇒ Object (also: #columns_hash)
Instance Method Details
#attribute(name, data_type, *args) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ninja_model/attribute_methods.rb', line 33 def attribute(name, data_type, *args) name = name.to_s opts = args. primary = opts.delete(:primary_key) self.primary_key = name if primary.eql?(true) default = args.first unless args.blank? new_attr = Attribute.new(name, data_type, opts) self.model_attributes = model_attributes + [new_attr] define_attribute_method name end |
#attribute_names ⇒ Object Also known as: column_names
54 55 56 |
# File 'lib/ninja_model/attribute_methods.rb', line 54 def attribute_names @attribute_names ||= model_attributes.map { |attribute| attribute.name } end |
#columns ⇒ Object
44 45 46 |
# File 'lib/ninja_model/attribute_methods.rb', line 44 def columns model_attributes end |
#model_attributes_hash ⇒ Object Also known as: columns_hash
48 49 50 |
# File 'lib/ninja_model/attribute_methods.rb', line 48 def model_attributes_hash @attributes_hash ||= HashWithIndifferentAccess[model_attributes.map { |attribute| [attribute.name, attribute] }] end |