Code cleanup
This commit is contained in:
parent
b251fd1a0e
commit
984059e63f
|
@ -21,7 +21,9 @@ module Ransack
|
|||
end
|
||||
|
||||
def translate(key, options = {})
|
||||
super or Translate.attribute(key.to_s, options.merge(:context => context))
|
||||
super or Translate.attribute(
|
||||
key.to_s, options.merge(:context => context)
|
||||
)
|
||||
end
|
||||
|
||||
def conditions
|
||||
|
@ -48,7 +50,7 @@ module Ransack
|
|||
alias :c= :conditions=
|
||||
|
||||
def [](key)
|
||||
if condition = conditions.detect {|c| c.key == key.to_s}
|
||||
if condition = conditions.detect { |c| c.key == key.to_s }
|
||||
condition
|
||||
else
|
||||
nil
|
||||
|
@ -56,7 +58,7 @@ module Ransack
|
|||
end
|
||||
|
||||
def []=(key, value)
|
||||
conditions.reject! {|c| c.key == key.to_s}
|
||||
conditions.reject! { |c| c.key == key.to_s }
|
||||
self.conditions << value
|
||||
end
|
||||
|
||||
|
@ -127,7 +129,9 @@ module Ransack
|
|||
when /^(g|c|m|groupings|conditions|combinator)=?$/
|
||||
true
|
||||
else
|
||||
name.split(/_and_|_or_/).select {|n| !@context.attribute_method?(n)}.empty?
|
||||
name.split(/_and_|_or_/)
|
||||
.select { |n| !@context.attribute_method?(n) }
|
||||
.empty?
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -155,9 +159,10 @@ module Ransack
|
|||
end
|
||||
|
||||
def inspect
|
||||
data =[['conditions', conditions], ['combinator', combinator]].reject { |e|
|
||||
e[1].blank?
|
||||
}.map { |v| "#{v[0]}: #{v[1]}" }.join(', ')
|
||||
data = [['conditions', conditions], ['combinator', combinator]]
|
||||
.reject { |e| e[1].blank? }
|
||||
.map { |v| "#{v[0]}: #{v[1]}" }
|
||||
.join(', ')
|
||||
"Grouping <#{data}>"
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module Ransack
|
||||
class Predicate
|
||||
attr_reader :name, :arel_predicate, :type, :formatter, :validator, :compound, :wants_array
|
||||
attr_reader :name, :arel_predicate, :type, :formatter, :validator,
|
||||
:compound, :wants_array
|
||||
|
||||
class << self
|
||||
|
||||
|
@ -24,11 +25,11 @@ module Ransack
|
|||
end
|
||||
|
||||
def detect_from_string(str)
|
||||
names_by_decreasing_length.detect {|p| str.end_with?("_#{p}")}
|
||||
names_by_decreasing_length.detect { |p| str.end_with?("_#{p}") }
|
||||
end
|
||||
|
||||
def name_from_attribute_name(attribute_name)
|
||||
names_by_decreasing_length.detect {|p| attribute_name.to_s.match(/_#{p}$/)}
|
||||
names_by_decreasing_length.detect { |p| attribute_name.to_s.match(/_#{p}$/) }
|
||||
end
|
||||
|
||||
def for_attribute_name(attribute_name)
|
||||
|
@ -42,9 +43,11 @@ module Ransack
|
|||
@arel_predicate = opts[:arel_predicate]
|
||||
@type = opts[:type]
|
||||
@formatter = opts[:formatter]
|
||||
@validator = opts[:validator] || lambda { |v| v.respond_to?(:empty?) ? !v.empty? : !v.nil? }
|
||||
@validator = opts[:validator] ||
|
||||
lambda { |v| v.respond_to?(:empty?) ? !v.empty? : !v.nil? }
|
||||
@compound = opts[:compound]
|
||||
@wants_array = opts[:wants_array] == true || @compound || ['in', 'not_in'].include?(@arel_predicate)
|
||||
@wants_array = opts[:wants_array] == true || @compound ||
|
||||
['in', 'not_in'].include?(@arel_predicate)
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
|
@ -66,7 +69,7 @@ module Ransack
|
|||
end
|
||||
|
||||
def validate(vals, type = @type)
|
||||
vals.select {|v| validator.call(type ? v.cast(type) : v.value)}.any?
|
||||
vals.select { |v| validator.call(type ? v.cast(type) : v.value) }.any?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue