class Flowlink::FieldMethod
Represents a property of a domain object. For example, a price in a product. If you need to change how one of these is handled in a specific product, then you can use it as a new argument for a class which inherits from Flowlink::ObjectBase
, and invokes super in .initialize
Attributes
args[R]
block[R]
method_name[R]
Public Class Methods
merge(overrides, original)
click to toggle source
# File lib/flowlink_data/field_method.rb, line 16 def self.merge(overrides, original) overrides.inject(original) { |a, e| e.merge(a) } end
multi_new(methods)
click to toggle source
# File lib/flowlink_data/field_method.rb, line 9 def self.multi_new(methods) methods.map do |m| m = [m].flatten FieldMethod.new(m.shift, m) end end
new(method_name, *args)
click to toggle source
# File lib/flowlink_data/field_method.rb, line 20 def initialize(method_name, *args) @method_name = method_name.to_sym @args = args.to_a.flatten @block, @args = @args.partition { |arg| arg.is_a? Proc } @block = @block[0] end
Public Instance Methods
==(other)
click to toggle source
# File lib/flowlink_data/field_method.rb, line 27 def ==(other) return false unless other.is_a?(self.class) to_a == other.to_a end
merge(list)
click to toggle source
# File lib/flowlink_data/field_method.rb, line 32 def merge(list) # rename to #override, #hard_merge, or add #override alias? # This will put itself into a list of other FieldMethods and overwrite # an existing FM with the same name list.delete_if { |o_fm| o_fm.method_name == method_name } list << self end
send_to(sendable)
click to toggle source
# File lib/flowlink_data/field_method.rb, line 43 def send_to(sendable) # we can't splat procs, so this is necessary # TODO: use #to_a and reduce cases/enforce SRP on regular arg assembler case when block && args.empty? sendable.send(method_name, &block) when block && !args.empty? sendable.send(method_name, *args, &block) when !block && args.empty? sendable.send(method_name) when !block && !args.empty? sendable.send(method_name, *args) end end
to_a()
click to toggle source
# File lib/flowlink_data/field_method.rb, line 39 def to_a [method_name] + args + (@block.nil? ? [] : [@block]) end