Class: ProconBypassMan::Web::BaseModel
- Inherits:
-
Object
- Object
- ProconBypassMan::Web::BaseModel
- Defined in:
- lib/procon_bypass_man/web/models/base_model.rb
Direct Known Subclasses
Class Method Summary collapse
- .column_names ⇒ Object
- .column_names=(c) ⇒ Object
- .count ⇒ Numric
- .db ⇒ Object
- .table_name ⇒ Object
- .table_name=(value) ⇒ Object
Instance Method Summary collapse
-
#initialize(row) ⇒ BaseModel
constructor
A new instance of BaseModel.
- #table_name ⇒ Object
- #update!(attributes) ⇒ Object
Constructor Details
#initialize(row) ⇒ BaseModel
Returns a new instance of BaseModel.
4 5 6 7 8 |
# File 'lib/procon_bypass_man/web/models/base_model.rb', line 4 def initialize(row) @@column_names.each.with_index(0) do |name, index| self.public_send("#{name}=", row[index]) end end |
Class Method Details
.column_names ⇒ Object
23 24 25 26 |
# File 'lib/procon_bypass_man/web/models/base_model.rb', line 23 def self.column_names raise "need to define column_names" if not defined?(@@column_names) @@column_names end |
.column_names=(c) ⇒ Object
19 20 21 |
# File 'lib/procon_bypass_man/web/models/base_model.rb', line 19 def self.column_names=(c) @@column_names = c end |
.count ⇒ Numric
11 12 13 |
# File 'lib/procon_bypass_man/web/models/base_model.rb', line 11 def self.count db.execute("select count(*) from #{table_name}").first.first end |
.db ⇒ Object
15 16 17 |
# File 'lib/procon_bypass_man/web/models/base_model.rb', line 15 def self.db ProconBypassMan::Web::Db.db end |
.table_name ⇒ Object
28 29 30 31 |
# File 'lib/procon_bypass_man/web/models/base_model.rb', line 28 def self.table_name raise "need to define column_names" if not defined?(@@table_name) @@table_name end |
.table_name=(value) ⇒ Object
33 34 35 |
# File 'lib/procon_bypass_man/web/models/base_model.rb', line 33 def self.table_name=(value) @@table_name = value end |
Instance Method Details
#table_name ⇒ Object
37 38 39 |
# File 'lib/procon_bypass_man/web/models/base_model.rb', line 37 def table_name self.class.table_name end |
#update!(attributes) ⇒ Object
41 42 43 44 |
# File 'lib/procon_bypass_man/web/models/base_model.rb', line 41 def update!(attributes) c = attributes.map {|key, _value| "'#{key}' = ?" }.join(", ") self.class.db.execute("update #{table_name} set #{c}", attributes.map {|_key, value| value }) end |