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
25 26 27 |
# File 'lib/eco-rake/options/library.rb', line 25 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.
45 46 47 48 49 50 |
# File 'lib/eco-rake/options/library.rb', line 45 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 |
# 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.
36 37 38 |
# File 'lib/eco-rake/options/library.rb', line 36 def names setes.keys end |
.set?(name) ⇒ Boolean
30 31 32 33 |
# File 'lib/eco-rake/options/library.rb', line 30 def set?(name) raise "Expected String or Symbol. Given: #{name.class}" unless name.respond_to?(:to_sym) sets.key?(name.to_sym) end |