class ZabbixAPI_ParametersDSL
Attributes
required_params[R]
valid_params[R]
Public Class Methods
new(other_validparams,other_requiredparams)
click to toggle source
# File api_classes/api_dsl.rb, line 37 def initialize(other_validparams,other_requiredparams) @other_valid_parameters=other_validparams @other_required_parameters=other_requiredparams @valid_params=[] @required_params=[] end
Public Instance Methods
add(*params)
click to toggle source
# File api_classes/api_dsl.rb, line 50 def add(*params) location=caller.select {|i| i=~/api_classes\/dsl/}.first.split(":")[0..1].join(":") #Iterate through the parameters and check to see if it's in the valid parameters list #and check to see if it's been given before. params.delete_if do |param| if @valid_params.include? param warn("Parameter '#{param}' is already a valid parameter, skipping: #{location}") true else false end end @valid_params+=params @valid_params.flatten! end
from(var)
click to toggle source
Function to provide some syntactic sugar for the DSL
# File api_classes/api_dsl.rb, line 72 def from(var) var end
inherit(ver)
click to toggle source
Inherit the valid and required parameters from the version string ver
# File api_classes/api_dsl.rb, line 45 def inherit(ver) @valid_params=@other_valid_parameters[ver] || [] @required_params=@other_required_parameters[ver] || [] end
remove(*params)
click to toggle source
# File api_classes/api_dsl.rb, line 66 def remove(*params) @valid_params-=params @required_params-=params end
requires(*params)
click to toggle source
Append the parameters given to the required parameters list.
# File api_classes/api_dsl.rb, line 92 def requires(*params) location=caller.select {|i| i=~/api_classes\/dsl/}.first.split(":")[0..1].join(":") #Iterate through the parameters and check to see if it's in the valid parameters list #and check to see if it's been given before. params.delete_if do |param| if !@valid_params.include? param raise InvalidRequiredParameter.new("Parameter '#{param}' is not in the valid list of parameters: #{location}") end if @required_params.include? param warn("Parameter '#{param}' is already a required parameter, skipping: #{location}") true else false end end @required_params+=params @required_params.flatten! end
set_requires(*params)
click to toggle source
Set the list of required parameters to the parameter list
# File api_classes/api_dsl.rb, line 77 def set_requires(*params) location=caller.select {|i| i=~/api_classes\/dsl/}.first.split(":")[0..1].join(":") #Iterate through the parameters and check to see if it's in the valid parameters list #and check to see if it's been given before. params.each do |param| if !@valid_params.include? param raise InvalidRequiredParameter.new("Parameter '#{param}' is not in the valid list of parameters: #{location}") end end @required_params=params @required_params.flatten! end