class MandrillQueue::Variables::Internal

Public Class Methods

new(values = nil, &block) click to toggle source
# File lib/mandrill_queue/variables.rb, line 22
def initialize(values = nil, &block)
        @_variables = values if values.is_a?(Hash)
        @_variables ||= {}
        dsl(&block) if block_given?
end

Public Instance Methods

[](key) click to toggle source
# File lib/mandrill_queue/variables.rb, line 55
def [](key)
        @_variables[key]
end
[]=(key, value) click to toggle source
# File lib/mandrill_queue/variables.rb, line 59
def []=(key, value)
        @_variables[key.to_sym] = value
end
merge!(hash) click to toggle source
# File lib/mandrill_queue/variables.rb, line 79
def merge!(hash)
        @_variables.merge!(hash)
end
method_missing(method, *args, &block) click to toggle source
# File lib/mandrill_queue/variables.rb, line 83
def method_missing(method, *args, &block)
        if method.to_s.end_with?('=')
                method = method.to_s.chomp('=').to_sym
        end

        if args.count > 0
                @_variables[method] = args.first
                self
        else
                raise VariableNotSetError, "#{method} has not been set." \
                        unless @_variables.has_key?(method)
                @_variables[method]
        end
end
respond_to?(method) click to toggle source
Calls superclass method
# File lib/mandrill_queue/variables.rb, line 30
def respond_to?(method)
        super || @_variables.has_key?(method)
end
set!(hash, options = {}) click to toggle source
# File lib/mandrill_queue/variables.rb, line 63
              def set!(hash, options = {})
                      case hash
                      when Hash
@_variables = hash.to_hash.symbolize_keys
                      when Array
                              options[:name_key] ||= :name
                              options[:content_key] ||= :content
                              @_variables = {}
                              hash.dup.each do |obj|
                                      obj.symbolize_keys!
                                      @_variables[obj[options[:name_key]].to_sym] = obj[options[:content_key]]
                              end
                      end
                      self
              end
to_hash(options = {}) click to toggle source
# File lib/mandrill_queue/variables.rb, line 34
def to_hash(options = {})
        if options.has_key?(:include_nils) && options[:include_nils]
                @_variables
        else
                @_variables.reject { |k, v| v.nil? }
        end
end
to_key_value_array(options = {}) click to toggle source
# File lib/mandrill_queue/variables.rb, line 42
def to_key_value_array(options = {})
        options[:name_key] ||= :name
        options[:content_key] ||= :content

        result = []
        @_variables.each do |k, v|
                if !v.nil? || options[:include_nils]
                        result.push({options[:name_key] => k.to_s, options[:content_key] => v})
                end
        end unless @_variables.nil?
        result
end