Sha256: 90ecc35725e6a4265d400c53ba20d3e71d55932a52204f398f748c95e6837bef

Contents?: true

Size: 973 Bytes

Versions: 1

Compression:

Stored size: 973 Bytes

Contents

module Relax
  class Context
    attr_reader :parameters

    def initialize(parameters=[]) # :nodoc:
      @parameters = parameters
    end

    def evaluate(&block) # :nodoc:
      instance_eval(&block)
    end

    def parameter(name, options={})
      unless @parameters.find { |parameter| parameter.name == name }
        @parameters << Parameter.new(name, options)
      else
        raise ArgumentError.new("Duplicate parameter '#{name}'.")
      end
    end

    def set(name, value)
      if parameter = @parameters.find { |parameter| parameter.name == name }
        parameter.value = value
      end
    end

    def parser(root, options={}, &block) # :nodoc:
      @parser ||= Relief::Parser.new(root, options, &block)
    end

    def parse(response) # :nodoc:
      @parser.parse(response)
    end

    def clone # :nodoc:
      cloned_parameters = @parameters.collect { |parameter| parameter.clone }
      self.class.new(cloned_parameters)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
relax-0.1.0 lib/relax/context.rb