Module: Shackles::ConnectionSpecification

Defined in:
lib/shackles/connection_specification.rb

Defined Under Namespace

Classes: CacheCoherentHash

Instance Method Summary collapse

Instance Method Details

#configObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/shackles/connection_specification.rb', line 49

def config
  @current_config = nil if Shackles.environment != @current_config_environment || Shackles.global_config_sequence != @current_config_sequence
  return @current_config if @current_config

  @current_config_environment = Shackles.environment
  @current_config_sequence = Shackles.global_config_sequence
  config = @config.dup
  if @config.has_key?(Shackles.environment)
    env_config = @config[Shackles.environment]
    # an array of databases for this environment; for now, just choose the first non-nil element
    if env_config.is_a?(Array)
      env_config = env_config.detect { |individual_config| !individual_config.nil? }
    end
    config.merge!(env_config.symbolize_keys)
  end

  config.keys.each do |key|
    next unless config[key].is_a?(String)
    config[key] = config[key] % config
  end

  config.merge!(Shackles.global_config)

  @current_config = CacheCoherentHash.new(self)
  @current_config.replace(config)

  @current_config
end

#config=(value) ⇒ Object



78
79
80
81
# File 'lib/shackles/connection_specification.rb', line 78

def config=(value)
  @config = value
  @current_config = nil
end

#initialize(name, config, adapter_method) ⇒ Object



35
36
37
# File 'lib/shackles/connection_specification.rb', line 35

def initialize(config, adapter_method)
  super(config.deep_symbolize_keys, adapter_method)
end

#initialize_dup(original) ⇒ Object



44
45
46
47
# File 'lib/shackles/connection_specification.rb', line 44

def initialize_dup(original)
  @current_config = nil
  super
end