Module: NinjaModel::AttributeMethods::ClassMethods

Defined in:
lib/ninja_model/attribute_methods.rb

Instance Method Summary collapse

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.extract_options!
  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_namesObject 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

#columnsObject



44
45
46
# File 'lib/ninja_model/attribute_methods.rb', line 44

def columns
  model_attributes
end

#model_attributes_hashObject 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