Class: ForestLiana::SchemaUtils
- Inherits:
-
Object
- Object
- ForestLiana::SchemaUtils
- Defined in:
- app/services/forest_liana/schema_utils.rb
Class Method Summary collapse
- .associations(active_record_class) ⇒ Object
- .find_model_from_collection_name(collection_name) ⇒ Object
- .many_associations(active_record_class) ⇒ Object
- .one_associations(active_record_class) ⇒ Object
- .tables_names ⇒ Object
Class Method Details
.associations(active_record_class) ⇒ Object
4 5 6 7 8 |
# File 'app/services/forest_liana/schema_utils.rb', line 4 def self.associations(active_record_class) active_record_class .reflect_on_all_associations .select {|a| !polymorphic?(a)} end |
.find_model_from_collection_name(collection_name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/forest_liana/schema_utils.rb', line 22 def self.find_model_from_collection_name(collection_name) model = nil ForestLiana.models.each do |subclass| if subclass.abstract_class? model = self.find_model_from_abstract_class(subclass, collection_name) elsif ForestLiana.name_for(subclass) == collection_name model = subclass.base_class end break if model end model end |
.many_associations(active_record_class) ⇒ Object
16 17 18 19 20 |
# File 'app/services/forest_liana/schema_utils.rb', line 16 def self.many_associations(active_record_class) self.associations(active_record_class).select do |x| [:has_many, :has_and_belongs_to_many].include?(x.macro) end end |
.one_associations(active_record_class) ⇒ Object
10 11 12 13 14 |
# File 'app/services/forest_liana/schema_utils.rb', line 10 def self.one_associations(active_record_class) self.associations(active_record_class).select do |x| [:has_one, :belongs_to].include?(x.macro) end end |
.tables_names ⇒ Object
38 39 40 |
# File 'app/services/forest_liana/schema_utils.rb', line 38 def self.tables_names ActiveRecord::Base.connection.tables end |