class Togl::Config
Attributes
adapters[RW]
default_adapters[RW]
features[RW]
Public Class Methods
new(args = {}, &block)
click to toggle source
# File lib/togl/config.rb, line 5 def initialize(args = {}, &block) @features = args.fetch(:features, []) @adapters = args.fetch(:adapters, {}) @default_adapters = args[:default_adapters] instance_eval(&block) if block_given? end
Public Instance Methods
feature(name, opts = {})
click to toggle source
Commands
# File lib/togl/config.rb, line 15 def feature(name, opts = {}) name = name.to_sym opts = { name: name, config: self, adapters: default_adapters }.merge(opts) features.push(Feature.new(opts)) self end
fetch(name)
click to toggle source
# File lib/togl/config.rb, line 37 def fetch(name) name = name.to_sym features.detect do |feature| feature.name.equal?(name) end.tap do |feature| if feature.nil? raise InvalidFeatureName, "No such configured feature: `#{name}'" end end end
fetch_adapter(name)
click to toggle source
# File lib/togl/config.rb, line 48 def fetch_adapter(name) adapters.fetch(name.to_sym) end
off?(name)
click to toggle source
# File lib/togl/config.rb, line 56 def off?(name) !on?(name) end
on?(name)
click to toggle source
# File lib/togl/config.rb, line 52 def on?(name) fetch(name).on? end
use(adapter)
click to toggle source
# File lib/togl/config.rb, line 26 def use(adapter) adapters[adapter.name] = adapter self end