Class: Plog::RecordAbstraction
- Inherits:
-
Object
- Object
- Plog::RecordAbstraction
- Defined in:
- lib/plog/record_abstraction.rb
Class Method Summary collapse
- .migration_class ⇒ Object
- .migration_constant ⇒ Object
- .migration_name ⇒ Object
- .record_class ⇒ Object
- .record_constant ⇒ Object
- .record_exists? ⇒ Boolean
- .record_name ⇒ Object
- .setup(table) ⇒ Object
Class Method Details
.migration_class ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/plog/record_abstraction.rb', line 27 def migration_class " class ::#{migration_name} < ActiveRecord::Migration def self.up create_table :#{@table[:table_name]} do |t| #{@table[:fields].map { |field, type| 't.' + type.to_s + ' :' + field.to_s } * "\n " } t.timestamps end end end " end |
.migration_constant ⇒ Object
45 46 47 48 |
# File 'lib/plog/record_abstraction.rb', line 45 def migration_constant eval(migration_class) eval('::' + migration_name) end |
.migration_name ⇒ Object
11 12 13 |
# File 'lib/plog/record_abstraction.rb', line 11 def migration_name "#{record_name}Migration" end |
.record_class ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/plog/record_abstraction.rb', line 19 def record_class " class ::#{record_name} < ActiveRecord::Base set_table_name :#{record_name.underscore} end " end |
.record_constant ⇒ Object
40 41 42 43 |
# File 'lib/plog/record_abstraction.rb', line 40 def record_constant eval(record_class) eval('::' + record_name) end |
.record_exists? ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/plog/record_abstraction.rb', line 50 def record_exists? ActiveRecord::Base.connection.execute('show tables').each do |record| return true if record.first == @table[:table_name].to_s end false end |
.record_name ⇒ Object
15 16 17 |
# File 'lib/plog/record_abstraction.rb', line 15 def record_name "#{@table[:table_name].to_s.camelize}" end |
.setup(table) ⇒ Object
7 8 9 |
# File 'lib/plog/record_abstraction.rb', line 7 def setup(table) @table = table end |