Class: Togl::Config
- Inherits:
-
Object
- Object
- Togl::Config
- Defined in:
- lib/togl/config.rb
Instance Attribute Summary collapse
-
#adapters ⇒ Object
Returns the value of attribute adapters.
-
#default_adapters ⇒ Object
Queries.
-
#features ⇒ Object
Returns the value of attribute features.
Instance Method Summary collapse
-
#feature(name, opts = {}) ⇒ Object
Commands.
- #fetch(name) ⇒ Object
- #fetch_adapter(name) ⇒ Object
-
#initialize(args = {}, &block) ⇒ Config
constructor
A new instance of Config.
- #off?(name) ⇒ Boolean
- #on?(name) ⇒ Boolean
- #use(adapter) ⇒ Object
Constructor Details
#initialize(args = {}, &block) ⇒ Config
Returns a new instance of Config.
5 6 7 8 9 10 11 |
# 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 |
Instance Attribute Details
#adapters ⇒ Object
Returns the value of attribute adapters.
3 4 5 |
# File 'lib/togl/config.rb', line 3 def adapters @adapters end |
#default_adapters ⇒ Object
Queries
33 34 35 |
# File 'lib/togl/config.rb', line 33 def default_adapters @default_adapters end |
#features ⇒ Object
Returns the value of attribute features.
3 4 5 |
# File 'lib/togl/config.rb', line 3 def features @features end |
Instance Method Details
#feature(name, opts = {}) ⇒ Object
Commands
15 16 17 18 19 20 21 22 23 24 |
# 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) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# 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) ⇒ Object
48 49 50 |
# File 'lib/togl/config.rb', line 48 def fetch_adapter(name) adapters.fetch(name.to_sym) end |
#off?(name) ⇒ Boolean
56 57 58 |
# File 'lib/togl/config.rb', line 56 def off?(name) !on?(name) end |
#on?(name) ⇒ Boolean
52 53 54 |
# File 'lib/togl/config.rb', line 52 def on?(name) fetch(name).on? end |
#use(adapter) ⇒ Object
26 27 28 29 |
# File 'lib/togl/config.rb', line 26 def use(adapter) adapters[adapter.name] = adapter self end |