Module: ModelExplorer

Defined in:
lib/model_explorer.rb,
lib/model_explorer/engine.rb,
lib/model_explorer/export.rb,
lib/model_explorer/import.rb,
lib/model_explorer/record.rb,
lib/model_explorer/scopes.rb,
lib/model_explorer/select.rb,
lib/model_explorer/version.rb,
lib/model_explorer/associations.rb,
lib/model_explorer/associations/base.rb,
lib/model_explorer/associations/many.rb,
lib/model_explorer/associations/singular.rb,
lib/generators/model_explorer/install_generator.rb,
app/controllers/model_explorer/models_controller.rb,
app/controllers/model_explorer/exports_controller.rb,
app/controllers/model_explorer/application_controller.rb

Defined Under Namespace

Modules: Associations, Scopes Classes: ApplicationController, Engine, Export, ExportsController, Import, InstallGenerator, ModelsController, Record, Select

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.association_scopes_enabled?TrueClass, FalseClass

Check if the association scopes are enabled true if the max_scopes_per_association is positive

Returns:

  • (TrueClass, FalseClass)


74
75
76
# File 'lib/model_explorer.rb', line 74

def self.association_scopes_enabled?
  max_scopes_per_association.positive?
end

.association_select_enabled?TrueClass, FalseClass

Check if the association select is enabled

Returns:

  • (TrueClass, FalseClass)

    true if the max_items_per_association is positive



67
68
69
# File 'lib/model_explorer.rb', line 67

def self.association_select_enabled?
  max_items_per_association.positive?
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (ModelExplorer)

    the object that the method was called on



38
39
40
# File 'lib/model_explorer.rb', line 38

def self.configure
  yield(self)
end

.import(json_record) ⇒ ActiveRecord::Base

Import a record and its associations from a JSON export

Parameters:

  • json_record (String)

    JSON record

Returns:

  • (ActiveRecord::Base)


45
46
47
48
49
# File 'lib/model_explorer.rb', line 45

def self.import(json_record)
  record_data = JSON.parse(json_record)

  Import.new(record_data).import
end

.modelsArray<Class>

List all models in the application excluding HABTM and abstract classes

Returns:

  • (Array<Class>)


54
55
56
57
58
59
60
61
62
# File 'lib/model_explorer.rb', line 54

def self.models
  ApplicationRecord.descendants.reject do |descendant|
    descendant_name = descendant.name

    descendant_name.blank? ||
      descendant_name.match(/HABTM/) ||
      descendant.abstract_class?
  end
end