class Cooperator::Context
Public Class Methods
new(attributes = {})
click to toggle source
# File lib/cooperator/context.rb, line 3 def initialize(attributes = {}) @_attributes = {_failure: false} attributes.each do |k, v| self[k] = v end end
Public Instance Methods
[](key)
click to toggle source
# File lib/cooperator/context.rb, line 47 def [](key) @_attributes[key] end
[]=(key, value)
click to toggle source
# File lib/cooperator/context.rb, line 43 def []=(key, value) @_attributes[key] = value end
errors()
click to toggle source
# File lib/cooperator/context.rb, line 11 def errors @_errors ||= Hash.new { |h, k| h[k] = [] } end
failure!(messages = {})
click to toggle source
# File lib/cooperator/context.rb, line 19 def failure!(messages = {}) messages.each do |key, message| if message.is_a? Array errors[key].push *message else errors[key].push message end end self[:_failure] = true end
failure?()
click to toggle source
# File lib/cooperator/context.rb, line 35 def failure? self[:_failure] end
include?(key)
click to toggle source
# File lib/cooperator/context.rb, line 39 def include?(key) @_attributes.include? key end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/cooperator/context.rb, line 51 def method_missing(method, *args, &block) if @_attributes.include? method puts Kernel.caller.first warn '[DEPRECATED] Cooperator::Context: Use hash-style accessors instead of methods.' return @_attributes.fetch method end name = String method if name.include? '=' warn '[DEPRECATED] Cooperator::Context: Use hash-style accessors instead of methods.' name.gsub!(/=/, '') @_attributes[:"#{name}"] = args.shift else super end end
respond_to_missing?(method, private = false)
click to toggle source
Calls superclass method
# File lib/cooperator/context.rb, line 72 def respond_to_missing?(method, private = false) name = String method name.gsub!(/=/, '') if name.include? '=' @_attributes.include?(:"#{name}") || super end
success!()
click to toggle source
# File lib/cooperator/context.rb, line 15 def success! self[:_failure] = false end
success?()
click to toggle source
# File lib/cooperator/context.rb, line 31 def success? not failure? end