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:



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:
  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:



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

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
# 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.



36
37
38
# File 'lib/eco-rake/options/library.rb', line 36

def names
  setes.keys
end

.set?(name) ⇒ Boolean

Returns:

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