Module: Mappd::ClassMethods
- Defined in:
- lib/mappd/mappd.rb
Instance Method Summary collapse
- #associations! ⇒ Object
- #commands ⇒ Object
- #field(name, type = :string, options = {}) ⇒ Object
- #index(name, options = {}) ⇒ Object
- #migrate! ⇒ Object
- #rename(from, to) ⇒ Object
- #timestamps ⇒ Object
Instance Method Details
#associations! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mappd/mappd.rb', line 23 def associations! reflect_on_all_associations.each do |association| case association.macro when :belongs_to commands << [:add_reference, [table_name, association.name, association.]] when :has_and_belongs_to_many commands << [:create_join_table, [table_name.to_sym, association.name]] end end end |
#commands ⇒ Object
41 42 43 |
# File 'lib/mappd/mappd.rb', line 41 def commands @commands ||= [] end |
#field(name, type = :string, options = {}) ⇒ Object
15 16 17 |
# File 'lib/mappd/mappd.rb', line 15 def field(name, type = :string, = {}) commands << [:add_column, [table_name, name, type, ]] end |
#index(name, options = {}) ⇒ Object
7 8 9 |
# File 'lib/mappd/mappd.rb', line 7 def index(name, = {}) commands << [:add_index, [table_name, name, ]] end |
#migrate! ⇒ Object
35 36 37 38 39 |
# File 'lib/mappd/mappd.rb', line 35 def migrate! create_table! associations! execute_commands! end |
#rename(from, to) ⇒ Object
11 12 13 |
# File 'lib/mappd/mappd.rb', line 11 def rename(from, to) commands << [:rename_column, [table_name, from, to]] end |
#timestamps ⇒ Object
19 20 21 |
# File 'lib/mappd/mappd.rb', line 19 def commands << [:add_timestamps, [table_name, null: true]] end |