lib/ronin/parameters/parameters.rb in ronin-0.0.9 vs lib/ronin/parameters/parameters.rb in ronin-0.1.0
- old
+ new
@@ -41,17 +41,17 @@
# Adds a new parameters with the specified _name_ and the given
# _options_ to the Class.
#
# parameter 'var'
#
- # parameter 'var', :value => 3, :description => 'my variable'
+ # parameter 'var', :default => 3, :description => 'my variable'
#
def parameter(name,options={})
name = name.to_sym
# add the parameter to the class params list
- params[name] = ClassParam.new(name,options[:description],options[:value])
+ params[name] = ClassParam.new(name,options[:description],options[:default])
# define the reader class method for the parameter
meta_def(name) do
params[name].value
end
@@ -71,14 +71,14 @@
# raised.
#
def get_param(name)
name = name.to_sym
- ancestors.each do |superclass|
- if superclass.include?(Parameters)
- if superclass.params.has_key?(name)
- return superclass.params[name]
+ ancestors.each do |ancestor|
+ if ancestor.include?(Parameters)
+ if ancestor.params.has_key?(name)
+ return ancestor.params[name]
end
end
end
raise(ParamNotFound,"parameter #{name.to_s.dump} was not found in class #{self.name.dump}",caller)
@@ -89,13 +89,13 @@
# exists, returns +false+ otherwise.
#
def has_param?(name)
name = name.to_sym
- ancestors.each do |superclass|
- if superclass.include?(Parameters)
- return true if superclass.params.has_key?(name)
+ ancestors.each do |ancestor|
+ if ancestor.include?(Parameters)
+ return true if ancestor.params.has_key?(name)
end
end
return false
end
@@ -103,13 +103,13 @@
#
# Iterates over all class parameters, passing each one to the
# specified _block_.
#
def each_param(&block)
- ancestors.each do |superclass|
- if superclass.include?(Parameters)
- superclass.params.each_value(&block)
+ ancestors.each do |ancestor|
+ if ancestor.include?(Parameters)
+ ancestor.params.each_value(&block)
end
end
return self
end
@@ -157,17 +157,17 @@
# Adds a new parameters with the specified _name_ and the given
# _options_ to the object.
#
# obj.parameter('var')
#
- # obj.parameter('var',:value => 3, :description => 'my variable')
+ # obj.parameter('var',:default => 3, :description => 'my variable')
#
def parameter(name,options={})
name = name.to_sym
# set the instance variable
- instance_variable_set("@#{name}",options[:value])
+ instance_variable_set("@#{name}",options[:default])
# add the new parameter
params[name] = InstanceParam.new(self,name,options[:description])
# define the reader method for the parameter
@@ -245,11 +245,22 @@
#
def param_value(name)
get_param(name).value
end
- protected
+ #
+ # Sets the values of the parameters listed in the specified _values_.
+ #
+ # obj.set_params(:rhost => 'www.example.com', :rport => 80)
+ # # => {:rhost=>"www.example.com", :rport=>80}
+ #
+ def set_params(values={})
+ values.each do |name,value|
+ get_param(name).value = value
+ end
+ end
+ protected
#
# Initializes the specified class _param_.
#
def initialize_param(param)