class RecordDiff::MatcherOptions
Handles the creation of Matcher
options.
Constants
- DEFAULT_OPTIONS
Attributes
after_id[R]
before_id[R]
options[R]
Public Class Methods
create_proc_chain(ary)
click to toggle source
# File lib/record_diff/matcher_options.rb, line 23 def self.create_proc_chain(ary) procs = ary.map { |a| create_transform_method a } proc do |input| procs.reduce(input) do |result, next_proc| next_proc.call(result) end end end
create_transform_method(arg = :itself)
click to toggle source
@return [Proc] @param [Proc,Symbol,Object] arg - symbol or proc
# File lib/record_diff/matcher_options.rb, line 15 def self.create_transform_method(arg = :itself) return proc { |ary| ary[1] } if arg == :second return transform_from_hsh arg if arg.is_a?(Hash) return create_proc_chain arg if arg.is_a?(Array) arg.to_proc end
new(options = {})
click to toggle source
# File lib/record_diff/matcher_options.rb, line 48 def initialize(options = {}) @options = DEFAULT_OPTIONS.merge options @before_id = @options[:before_id].to_proc @after_id = @options[:after_id].to_proc end
transform_from_hsh(hsh)
click to toggle source
Creates a proc based on the hash provided.
# File lib/record_diff/matcher_options.rb, line 33 def self.transform_from_hsh(hsh) return proc { |hash| hash.slice(*hsh[:keys]) } if hsh.keys == [:keys] if hsh.keys == [:attrs] return proc do |obj| attrs = hsh[:attrs] Hash[attrs.collect { |k| [k, obj.send(k)] }] end end raise StandardError, 'Unexpected Hash Config' end
Public Instance Methods
after_transform()
click to toggle source
# File lib/record_diff/matcher_options.rb, line 59 def after_transform @after_transform ||= self.class.create_transform_method options[:after_transform] end
before_transform()
click to toggle source
# File lib/record_diff/matcher_options.rb, line 54 def before_transform @before_transform ||= self.class.create_transform_method options[:before_transform] end