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.30 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.29 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.28 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.27 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.26 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.25 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.23 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.22 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.20 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.19 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.18 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.17 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.16 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.15 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.14 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.13 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.12 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.11 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.10 app/services/forest_liana/schema_utils.rb
forest_liana-1.1.8 app/services/forest_liana/schema_utils.rb