Class: RakeFactory::ParameterSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_factory/parameter_set.rb

Instance Method Summary collapse

Constructor Details

#initializeParameterSet

Returns a new instance of ParameterSet.



6
7
8
# File 'lib/rake_factory/parameter_set.rb', line 6

def initialize
  @parameter_set = {}
end

Instance Method Details

#add(name, options) ⇒ Object



10
11
12
13
14
# File 'lib/rake_factory/parameter_set.rb', line 10

def add(name, options)
  parameter = Parameter.new(name, options)
  @parameter_set[parameter.name] = parameter
  parameter
end

#apply_defaults_to(instance) ⇒ Object



28
29
30
31
32
# File 'lib/rake_factory/parameter_set.rb', line 28

def apply_defaults_to(instance)
  @parameter_set.values.each do |parameter|
    parameter.apply_default_to(instance)
  end
end

#each(&block) ⇒ Object



20
21
22
# File 'lib/rake_factory/parameter_set.rb', line 20

def each(&block)
  @parameter_set.values.each(&block)
end

#enforce_requirements_on(instance) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rake_factory/parameter_set.rb', line 34

def enforce_requirements_on(instance)
  dissatisfied = @parameter_set.values.reject do |parameter|
    parameter.satisfied_by?(instance)
  end
  unless dissatisfied.empty?
    names = dissatisfied.map(&:name)
    names_string = names.join(',')
    pluralisation_string = names.length > 1 ? 's' : ''

    raise RequiredParameterUnset,
        "Required parameter#{pluralisation_string} #{names_string} unset."
  end
end

#find(name) ⇒ Object



16
17
18
# File 'lib/rake_factory/parameter_set.rb', line 16

def find(name)
  @parameter_set[name.to_sym]
end

#update_default_for(name, value) ⇒ Object



24
25
26
# File 'lib/rake_factory/parameter_set.rb', line 24

def update_default_for(name, value)
  find(name).default = value
end