Class: EcoRake::Options::Library
- Inherits:
-
Object
- Object
- EcoRake::Options::Library
- Extended by:
- Enumerable, RakeCommander::Base::ClassAutoLoader, RakeCommander::Base::ClassHelpers
- Defined in:
- lib/eco-rake/options/library.rb
Overview
Gathers all the option presets (EcoRake::Options::Set
) defined.
It works at class level and does lazy loading.
Class Method Summary collapse
-
.[](value) ⇒ EcoRake::Options::Set
Retrieve an options set.
-
.add(options_set) ⇒ EcoRake::Options::Set
Add a new options set.
-
.each(&block) ⇒ Object
Iterator.
-
.names ⇒ Array<Symbol>
Names list of all available option sets.
- .set?(name) ⇒ Boolean
Class Method Details
.[](value) ⇒ EcoRake::Options::Set
Retrieve an options set
26 27 28 |
# File 'lib/eco-rake/options/library.rb', line 26 def [](value) sets[to_name(value)] end |
.add(options_set) ⇒ EcoRake::Options::Set
Note:
- If it receives an
item_class
(Class
) it just adds it in - If it receives an object instance, it adds its class
Add a new options set.
47 48 49 50 51 52 |
# File 'lib/eco-rake/options/library.rb', line 47 def add() klass = .is_a?(Class)? : .class raise "Expecting #{item_class} child or instance. Given: #{klass}" unless klass <= item_class puts "Warning: redefining options set '#{set.name}'" if self[.name] sets[.name] = klass end |
.each(&block) ⇒ Object
Iterator
18 19 20 21 22 |
# File 'lib/eco-rake/options/library.rb', line 18 def each(&block) return to_enum(:each) unless block_given? sets.values.each(&block) end |
.names ⇒ Array<Symbol>
Returns names list of all available option sets.
38 39 40 |
# File 'lib/eco-rake/options/library.rb', line 38 def names sets.keys end |
.set?(name) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/eco-rake/options/library.rb', line 31 def set?(name) raise "Expected String or Symbol. Given: #{name.class}" unless name.respond_to?(:to_sym) sets.key?(name.to_sym) end |