78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/erector/needs.rb', line 78
def initialize(assigns = {})
super
assigned = assigns.keys
self.class.needed_defaults.each do |name, value|
unless assigned.include?(name)
value = [NilClass, FalseClass, TrueClass, Fixnum, Float, Symbol].include?(value.class) ? value : value.dup
instance_variable_set("@#{name}", value)
assigned << name
end
end
missing = self.class.needed_variables - assigned
unless missing.empty? || missing == [nil]
raise ArgumentError, "Missing parameter#{missing.size == 1 ? '' : 's'} for #{self.class.name}: #{missing.join(', ')}"
end
excess = assigned - self.class.needed_variables
unless self.class.needed_variables.empty? || excess.empty? || self.class.
raise ArgumentError, "Excess parameter#{excess.size == 1 ? '' : 's'} for #{self.class.name}: #{excess.join(', ')}"
end
end
|