class SwitchPoint::Config
Attributes
auto_writable[RW]
auto_writable?[RW]
Public Class Methods
new()
click to toggle source
# File lib/switch_point/config.rb, line 8 def initialize self.auto_writable = false end
Public Instance Methods
database_name(name, mode)
click to toggle source
# File lib/switch_point/config.rb, line 21 def database_name(name, mode) fetch(name)[mode] end
define_switch_point(name, config)
click to toggle source
# File lib/switch_point/config.rb, line 12 def define_switch_point(name, config) assert_valid_config!(config) switch_points[name] = config end
each_key(&block)
click to toggle source
# File lib/switch_point/config.rb, line 39 def each_key(&block) switch_points.each_key(&block) end
fetch(name)
click to toggle source
# File lib/switch_point/config.rb, line 31 def fetch(name) switch_points.fetch(name) end
keys()
click to toggle source
# File lib/switch_point/config.rb, line 35 def keys switch_points.keys end
model_name(name, mode)
click to toggle source
# File lib/switch_point/config.rb, line 25 def model_name(name, mode) if fetch(name)[mode] "#{name}_#{mode}".camelize end end
switch_points()
click to toggle source
# File lib/switch_point/config.rb, line 17 def switch_points @switch_points ||= {} end
Private Instance Methods
assert_valid_config!(config)
click to toggle source
# File lib/switch_point/config.rb, line 45 def assert_valid_config!(config) unless config.key?(:readonly) || config.key?(:writable) raise ArgumentError.new(':readonly or :writable must be specified') end if config.key?(:readonly) unless config[:readonly].is_a?(Symbol) raise TypeError.new(":readonly's value must be Symbol") end end if config.key?(:writable) unless config[:writable].is_a?(Symbol) raise TypeError.new(":writable's value must be Symbol") end end nil end