Sha256: 85a990cdb775781beb1757b72b3b6c0634e17fc85b2a32e674ac3d417ef26b1e

Contents?: true

Size: 640 Bytes

Versions: 41

Compression:

Stored size: 640 Bytes

Contents

module ForestLiana
  class SchemaUtils

    def self.associations(active_record_class)
      active_record_class
        .reflect_on_all_associations
        .select {|a| !polymorphic?(a)}
    end

    def self.find_model_from_table_name(table_name)
      (table_name.classify.constantize rescue nil) ||
        (table_name.capitalize.constantize rescue nil) ||
        (table_name.sub('_', '/').camelize.singularize.constantize rescue nil)
    end

    def self.tables_names
      ActiveRecord::Base.connection.tables
    end

    private

    def self.polymorphic?(association)
      association.options[:polymorphic]
    end

  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
forest_liana-1.1.7 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.6 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.5 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.4 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.3 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.2 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.1 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.0 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.11 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.10 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.8 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.7 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.6 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.5 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.4 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.3 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.2 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.1 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.0.beta7 app/services/forest_liana/schema_utils.rb
forest_liana-1.0.0.beta6 app/services/forest_liana/schema_utils.rb