Module: Bj::Table::ClassMethods
- Defined in:
- lib/bj/table.rb
Instance Method Summary collapse
- #content_column_names ⇒ Object
- #create_hash_for(options) ⇒ Object
- #down ⇒ Object
- #each(*a, &b) ⇒ Object
- #migration_class ⇒ Object
- #migration_code(classname = "BjMigration") ⇒ Object
- #reverse_each(*a, &b) ⇒ Object
- #up ⇒ Object
Instance Method Details
#content_column_names ⇒ Object
44 45 46 |
# File 'lib/bj/table.rb', line 44 def content_column_names @content_column_names = content_columns.map{|column| column.name} end |
#create_hash_for(options) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/bj/table.rb', line 48 def create_hash_for . hash = {} content_column_names.each do |key| key = key.to_s.to_sym hash[key] = [key] end hash end |
#down ⇒ Object
27 28 29 |
# File 'lib/bj/table.rb', line 27 def down migration_class.down end |
#each(*a, &b) ⇒ Object
58 59 60 |
# File 'lib/bj/table.rb', line 58 def each *a, &b list.each *a, &b end |
#migration_class ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bj/table.rb', line 31 def migration_class table = self @migration_class ||= Class.new(ActiveRecord::Migration) do sc = class << self self end sc.module_eval{ attribute :table => table } sc.module_eval &table.migration end end |
#migration_code(classname = "BjMigration") ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bj/table.rb', line 10 def migration_code classname = "BjMigration" <<-code class #{ classname } < ActiveRecord::Migration def self.up Bj::Table.each{|table| table.up} end def self.down Bj::Table.reverse_each{|table| table.down} end end code end |
#reverse_each(*a, &b) ⇒ Object
62 63 64 |
# File 'lib/bj/table.rb', line 62 def reverse_each *a, &b list.reverse.each *a, &b end |
#up ⇒ Object
23 24 25 |
# File 'lib/bj/table.rb', line 23 def up migration_class.up end |