Module: SimpleMaster

Defined in:
lib/simple_master.rb,
lib/simple_master/loader.rb,
lib/simple_master/master.rb,
lib/simple_master/schema.rb,
lib/simple_master/storage.rb,
lib/simple_master/version.rb,
lib/simple_master/master/dsl.rb,
lib/simple_master/active_record.rb,
lib/simple_master/master/column.rb,
lib/simple_master/storage/table.rb,
lib/simple_master/master/editable.rb,
lib/simple_master/master/storable.rb,
lib/simple_master/storage/dataset.rb,
lib/simple_master/master/queryable.rb,
lib/simple_master/master/filterable.rb,
lib/simple_master/master/association.rb,
lib/simple_master/master/validatable.rb,
lib/simple_master/storage/test_table.rb,
lib/simple_master/loader/query_loader.rb,
lib/simple_master/loader/dataset_loader.rb,
lib/simple_master/loader/marshal_loader.rb,
lib/simple_master/storage/ondemand_table.rb,
lib/simple_master/active_record/extension.rb,
lib/simple_master/master/column/id_column.rb,
lib/simple_master/master/column/enum_column.rb,
lib/simple_master/master/column/json_column.rb,
lib/simple_master/master/column/time_column.rb,
lib/simple_master/master/column/float_column.rb,
lib/simple_master/master/column/string_column.rb,
lib/simple_master/master/column/symbol_column.rb,
lib/simple_master/master/column/bitmask_column.rb,
lib/simple_master/master/column/boolean_column.rb,
lib/simple_master/master/column/integer_column.rb,
lib/simple_master/master/column/sti_type_column.rb,
lib/simple_master/master/column/polymorphic_type_column.rb,
lib/simple_master/master/association/has_one_association.rb,
lib/simple_master/master/association/has_many_association.rb,
lib/simple_master/master/association/belongs_to_association.rb,
lib/simple_master/active_record/belongs_to_polymorphic_builder.rb,
lib/simple_master/active_record/preloader_association_extension.rb,
lib/simple_master/master/association/has_many_through_association.rb,
lib/simple_master/active_record/belongs_to_polymorphic_association.rb,
lib/simple_master/master/association/belongs_to_polymorphic_association.rb,
lib/simple_master/active_record/belongs_to_master_polymorphic_reflection.rb

Defined Under Namespace

Modules: ActiveRecord, Storage Classes: Loader, Master, Schema

Constant Summary collapse

EMPTY_ARRAY =
[].freeze
EMPTY_HASH =
{}.freeze
VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.database_available?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/simple_master.rb', line 36

def self.database_available?
  # Raises an error if the DB is missing
  ::ActiveRecord::Base.connection.verify!

  true
rescue
  false
end

.init(for_test: false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/simple_master.rb', line 21

def self.init(for_test: false)
  is_database_available = database_available?
  unless is_database_available
    SimpleMaster.logger.warn "DB not connected. SimpleMaster will not initialize associations to ActiveRecord."
  end

  yield if block_given?

  targets.each { |klass| klass.init(is_database_available, for_test: for_test) }
end

.loggerObject



13
14
15
16
17
18
19
# File 'lib/simple_master.rb', line 13

def self.logger
  if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
    Rails.logger
  else
    @logger ||= Logger.new($stdout)
  end
end

.targetsObject



32
33
34
# File 'lib/simple_master.rb', line 32

def self.targets
  Master.descendants.reject(&:abstract_class)
end

.use_dataset(dataset) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/simple_master.rb', line 45

def self.use_dataset(dataset)
  former_dataset = $current_dataset
  $current_dataset = dataset
  yield
ensure
  $current_dataset = former_dataset
end