Class: EacRailsUtils::Models::Tableless

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Associations, ActiveModel::Model
Defined in:
lib/eac_rails_utils/models/tableless.rb

Defined Under Namespace

Classes: AttributesBuilder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ Tableless

Returns a new instance of Tableless.


23
24
25
# File 'lib/eac_rails_utils/models/tableless.rb', line 23

def initialize(values = {})
  super(build_attributes(values))
end

Class Method Details

.columnsObject


14
15
16
# File 'lib/eac_rails_utils/models/tableless.rb', line 14

def columns
  attribute_set.each.to_a
end

.columns_namesObject


18
19
20
# File 'lib/eac_rails_utils/models/tableless.rb', line 18

def columns_names
  columns.map(&:name)
end

Instance Method Details

#[](attr) ⇒ Object

need hash like accessor, used internal Rails


32
33
34
# File 'lib/eac_rails_utils/models/tableless.rb', line 32

def [](attr)
  send(attr)
end

#[]=(attr, value) ⇒ Object

need hash like accessor, used internal Rails


37
38
39
# File 'lib/eac_rails_utils/models/tableless.rb', line 37

def []=(attr, value)
  send("#{attr}=", value)
end

#attributes=(values) ⇒ Object


27
28
29
# File 'lib/eac_rails_utils/models/tableless.rb', line 27

def attributes=(values)
  super(build_attributes(values))
end

#save!Object


41
42
43
# File 'lib/eac_rails_utils/models/tableless.rb', line 41

def save!
  save || raise("#{self.class}.save failed: #{errors.messages}")
end