Module: RemoteDb::Concerns::Configurable::ClassMethods

Defined in:
lib/remote_db/concerns/configurable.rb

Instance Method Summary collapse

Instance Method Details

#configurationObject



22
23
24
# File 'lib/remote_db/concerns/configurable.rb', line 22

def configuration
  @configuration ||= RemoteDb::Configuration.new
end

#configure(config_hash = nil) {|configuration| ... } ⇒ Object

Yields:



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/remote_db/concerns/configurable.rb', line 9

def configure(config_hash = nil)
  if config_hash
    config_hash.each do |k,v|
      setter = "#{k}="
      if configuration.respond_to?(setter )
        configuration.send(setter , v)
      end
    end
  end

  yield(configuration) if block_given?
end

#load_models!(options = { readonly: true }) ⇒ Object



34
35
36
37
38
# File 'lib/remote_db/concerns/configurable.rb', line 34

def load_models!(options = { readonly: true })
  clear_old_models
  define_base_record(options)
  send(:require_models) if respond_to?(:require_models)
end

#without_readonlyObject



26
27
28
29
30
31
32
# File 'lib/remote_db/concerns/configurable.rb', line 26

def without_readonly
  raise ForbiddenActionException unless configuration.environment == :test

  load_models!(readonly: false)
  yield
  load_models!(readonly: true)
end