lib/hermod/xml_section_builder.rb
def create_method(name, mutators, validators, options = {}, &block)
      raise DuplicateNodeError, "#{name} is already defined" if @node_order.include? name
      @node_order << name
      xml_name = options.fetch(:xml_name, name.to_s.camelize)

      @new_class.send :define_method, name do |value, attributes = {}|
        mutators.each { |mutator| value, attributes = mutator.mutate!(value, attributes, self) }
        begin
          validators.each { |validator| validator.valid?(value, attributes) }
        rescue InvalidInputError => ex
          raise InvalidInputError, "#{name} #{ex.message}"
        end

        value, attributes = instance_exec(value, attributes, &block)
        if value.present?
          nodes[name] << XmlNode.new(xml_name, value, attributes).rename_attributes(options[:attributes])
        end
      end
    end
# Private: creates a method with a given name that uses a set of mutators
# and a set of validators to change and validate the input according to
# certain options. This is used to implement all the node type methods.
#
# name -       the name of the new method
# mutators -   an array of InputMutator objects (normally one) that change the value and attributes in some way
# validators - an array of Validator::Base subclasses that are applied to the value and attributes and raise
#              errors under given conditions
# block -      a block that takes the value and attributes and does any post-validation mutation on them
#
# Returns nothing you should rely on
creates a method with a given name that uses a set of mutators
and a set of validators to change and validate the input according to
certain options. This is used to implement all the node type methods.

the name of the new method
mutators -   an array of InputMutator objects (normally one) that change the value and attributes in some way
validators - an array of Validator::Base subclasses that are applied to the value and attributes and raise
errors under given conditions
block -      a block that takes the value and attributes and does any post-validation mutation on them

Returns nothing you should rely on
creates a method with a given name that uses a set of mutators and a set of validators to change and validate the input according to certain options . This is used to implement all the node type methods . the name of the new method mutators - an array of InputMutator objects ( normally one ) that change the value and attributes in some way validators - an array of Validator :: Base subclasses that are applied to the value and attributes and raise errors under given conditions block - a block that takes the value and attributes and does any post - validation mutation on them Returns nothing you should rely on
def create_method(name, mutators, validators, options = {}, &block)
      raise DuplicateNodeError, "#{name} is already defined" if @node_order.include? name
      @node_order << name
      xml_name = options.fetch(:xml_name, name.to_s.camelize)
      @new_class.send :define_method, name do |value, attributes = {}|
        mutators.each { |mutator| value, attributes = mutator.mutate!(value, attributes, self) }
        begin
          validators.each { |validator| validator.valid?(value, attributes) }
        rescue InvalidInputError => ex
          raise InvalidInputError, "#{name} #{ex.message}"
        end
        value, attributes = instance_exec(value, attributes, &block)
        if value.present?
          nodes[name] << XmlNode.new(xml_name, value, attributes).rename_attributes(options[:attributes])
        end
      end
    end
def create_method ( name , mutators , validators , options = { } , & block ) raise DuplicateNodeError , "#{name} is already defined" if @node_order . include? name @node_order << name xml_name = options . fetch ( :xml_name , name . to_s . camelize ) @new_class . send :define_method , name do | value , attributes = { } | mutators . each { | mutator | value , attributes = mutator . mutate! ( value , attributes , self ) } begin validators . each { | validator | validator . valid? ( value , attributes ) } rescue InvalidInputError => ex raise InvalidInputError , "#{name} #{ex.message}" end value , attributes = instance_exec ( value , attributes , & block ) if value . present? nodes [ name ] << XmlNode . new ( xml_name , value , attributes ) . rename_attributes ( options [ :attributes ] ) end end end
Private: creates a method with a given name that uses a set of mutators
and a set of validators to change and validate the input according to
certain options.
Private : creates a method with a given name that uses a set of mutators and a set of validators to change and validate the input according to certain options .
name
mutators
validators
options
block