Class: EcoRake::Options::Library

Inherits:
Object
  • Object
show all
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

Class Method Details

.[](value) ⇒ EcoRake::Options::Set

Retrieve an options set

Returns:



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:
  1. If it receives an item_class (Class) it just adds it in
  2. If it receives an object instance, it adds its class

Add a new options set.

Returns:



47
48
49
50
51
52
# File 'lib/eco-rake/options/library.rb', line 47

def add(options_set)
  klass = options_set.is_a?(Class)? options_set : options_set.class
  raise "Expecting #{item_class} child or instance. Given: #{klass}" unless klass <= item_class
  puts "Warning: redefining options set '#{set.name}'"               if self[options_set.name]
  sets[options_set.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

.namesArray<Symbol>

Returns names list of all available option sets.

Returns:

  • (Array<Symbol>)

    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

Returns:

  • (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