Module: Mappd::ClassMethods
- Defined in:
- lib/mappd/mappd.rb
Instance Method Summary collapse
- #associations! ⇒ Object
- #commands ⇒ Object
- #drop(name) ⇒ Object
- #field(name, type = :string, options = {}) ⇒ Object
- #index(name, options = {}) ⇒ Object
- #migrate! ⇒ Object
- #rename(from, to) ⇒ Object
- #timestamps ⇒ Object
Instance Method Details
#associations! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mappd/mappd.rb', line 29 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
48 49 50 |
# File 'lib/mappd/mappd.rb', line 48 def commands @commands ||= [] end |
#drop(name) ⇒ Object
17 18 19 |
# File 'lib/mappd/mappd.rb', line 17 def drop(name) commands << [:remove_column, [table_name, name]] end |
#field(name, type = :string, options = {}) ⇒ Object
21 22 23 |
# File 'lib/mappd/mappd.rb', line 21 def field(name, type = :string, = {}) commands << [:add_column, [table_name, name, type, { ** }]] end |
#index(name, options = {}) ⇒ Object
9 10 11 |
# File 'lib/mappd/mappd.rb', line 9 def index(name, = {}) commands << [:add_index, [table_name, name, { ** }]] end |
#migrate! ⇒ Object
42 43 44 45 46 |
# File 'lib/mappd/mappd.rb', line 42 def migrate! create_table! associations! execute_commands! end |
#rename(from, to) ⇒ Object
13 14 15 |
# File 'lib/mappd/mappd.rb', line 13 def rename(from, to) commands << [:rename_column, [table_name, from, to]] end |
#timestamps ⇒ Object
25 26 27 |
# File 'lib/mappd/mappd.rb', line 25 def commands << [:add_timestamps, [table_name, { null: true }]] end |