module Periscope
Public Instance Methods
periscope(params = {})
click to toggle source
# File lib/periscope.rb, line 7 def periscope(params = {}) params.inject(periscope_default_scope) do |chain, (scope, param)| periscope_call(chain, scope.to_s, param) end end
scope_accessible(*scopes)
click to toggle source
# File lib/periscope.rb, line 2 def scope_accessible(*scopes) options = scopes.last.is_a?(Hash) ? scopes.pop : {} scopes.each { |s| periscope_options[s.to_s] = options } end
Private Instance Methods
periscope_blank?(value)
click to toggle source
# File lib/periscope.rb, line 44 def periscope_blank?(value) return true unless value value.respond_to?(:blank?) ? value.blank? : value.empty? end
periscope_call(chain, scope, param)
click to toggle source
# File lib/periscope.rb, line 23 def periscope_call(chain, scope, param) return chain unless options = periscope_options[scope] method = periscope_method(scope, options) values = periscope_values(param, options) if periscope_ignore?(values.first, options) chain else options[:boolean] ? chain.send(method) : chain.send(method, *values) end end
periscope_default_scope()
click to toggle source
# File lib/periscope.rb, line 19 def periscope_default_scope raise NotImplementedError end
periscope_ignore?(value, options)
click to toggle source
# File lib/periscope.rb, line 36 def periscope_ignore?(value, options) if options[:ignore_blank] periscope_blank?(value) elsif options[:boolean] !value end end
periscope_method(scope, options)
click to toggle source
# File lib/periscope.rb, line 49 def periscope_method(scope, options) options[:method] || [options[:prefix], scope, options[:suffix]].compact.join end
periscope_options()
click to toggle source
# File lib/periscope.rb, line 15 def periscope_options @periscope_options ||= {} end
periscope_values(param, options)
click to toggle source
# File lib/periscope.rb, line 53 def periscope_values(param, options) options[:parser] ? options[:parser].call(param) : [param] end