Module: Permissify::ModelClass
Instance Method Summary collapse
- #create_seeds(seed_specifications) ⇒ Object
- #create_with_id(table, id, name) ⇒ Object
- #force_seed_id(table, permissions_model, id) ⇒ Object
- #locate(id, name) ⇒ Object
- #underscored_name_symbol(name) ⇒ Object
Instance Method Details
#create_seeds(seed_specifications) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/permissify/model_class.rb', line 4 def create_seeds(seed_specifications) seed_specifications.each do |id, name| = locate(id, name) . = send("#{underscored_name_symbol(name)}_permissions") # interface methods needed for each seeded model .save end end |
#create_with_id(table, id, name) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/permissify/model_class.rb', line 12 def create_with_id(table, id, name) = send("#{underscored_name_symbol(name)}_permissions") = new .name = name . = .save force_seed_id(table, , id) # interface method : force_seed_id find(id) end |
#force_seed_id(table, permissions_model, id) ⇒ Object
22 23 24 25 |
# File 'lib/permissify/model_class.rb', line 22 def force_seed_id(table, , id) # not sure if this is still needed, may differ depending on db adapter (written against mysql) ActiveRecord::Base.connection.execute "UPDATE #{table}s SET id=#{id} WHERE id=#{.id};" end |
#locate(id, name) ⇒ Object
27 28 29 30 |
# File 'lib/permissify/model_class.rb', line 27 def locate(id, name) model_with_id = find_by_id(id) # interface method : ActiveRecord::Base.find_by_id model_with_id ||= send("create_#{underscored_name_symbol(name)}") # interface methods needed for each seeded model end |
#underscored_name_symbol(name) ⇒ Object
32 33 34 |
# File 'lib/permissify/model_class.rb', line 32 def underscored_name_symbol(name) name.to_s.downcase.gsub(':','').gsub('-','_').gsub(' ','_').gsub(/__*/,'_') end |