class Through::Pipe
Public Class Methods
new(object, context = {})
click to toggle source
# File lib/through.rb, line 5 def initialize(object, context = {}) @object = object @context = context end
pipe(options = {}) { |query, context| ... }
click to toggle source
# File lib/through.rb, line 34 def self.pipe(options = {}) pipes << options.merge({ scope: -> (query, context) { yield(query, context) } }) end
pipe_with(name, options = {}) { |query, arg, context| ... }
click to toggle source
# File lib/through.rb, line 22 def self.pipe_with(name, options = {}) pipes_with[name] = options.merge({ scope: -> (query, arg, context) { yield(query, arg, context) } }) end
pipe_without(name, options = {}) { |query, arg, context| ... }
click to toggle source
# File lib/through.rb, line 28 def self.pipe_without(name, options = {}) pipes_without[name] = options.merge({ scope: -> (query, arg, context) { yield(query, arg, context) } }) end
pipes()
click to toggle source
# File lib/through.rb, line 18 def self.pipes @pipes ||= [] end
pipes_with()
click to toggle source
# File lib/through.rb, line 10 def self.pipes_with @pipes_with ||= {} end
pipes_without()
click to toggle source
# File lib/through.rb, line 14 def self.pipes_without @pipes_without ||= {} end
Public Instance Methods
should_filter?(filter, params)
click to toggle source
# File lib/through.rb, line 48 def should_filter?(filter, params) if (filter.has_key?(:if)) filter[:if].call(params, @context) else true end end
should_filter_pipe?(filter)
click to toggle source
# File lib/through.rb, line 40 def should_filter_pipe?(filter) if (filter.has_key?(:if)) filter[:if].call(@context) else true end end
through(params = {})
click to toggle source
# File lib/through.rb, line 82 def through(params = {}) self.through_pipe self.through_without(params) self.through_with(params) @object end
through_pipe()
click to toggle source
# File lib/through.rb, line 56 def through_pipe self.class.pipes.each do |context_filter| if (self.should_filter_pipe?(context_filter)) @object = context_filter[:scope].call(@object, @context) end end end
through_with(params)
click to toggle source
# File lib/through.rb, line 64 def through_with(params) self.class.pipes_with.each do |without| key, value = without if (params.has_key?(key) && self.should_filter?(value, params[key])) @object = value[:scope].call(@object, params[key], @context) end end end
through_without(params)
click to toggle source
# File lib/through.rb, line 73 def through_without(params) self.class.pipes_without.each do |without| key, value = without if (!params.has_key?(key) && self.should_filter?(value, params)) @object = value[:scope].call(@object, params, @context) end end end