lib/gitter/base.rb in gitter-1.1.5 vs lib/gitter/base.rb in gitter-1.1.6
- old
+ new
@@ -1,6 +1,7 @@
require 'active_support/concern'
+require 'active_support/hash_with_indifferent_access'
require 'artdeco'
require 'gitter/filters.rb'
require 'gitter/facet.rb'
module Gitter
@@ -24,11 +25,11 @@
opts = args.extract_options!
@decorator = Artdeco::Decorator.new *args, opts
@params = @decorator.params.fetch(key){{}}.symbolize_keys
- @filters, @values, @facets = {}, {}, {}
+ @filters, @values, @facets = {}.with_indifferent_access, {}.with_indifferent_access, {}.with_indifferent_access
scope = opts.delete(:scope){nil}
@options = opts.dup
instance_eval &self.class.grid
@@ -75,11 +76,11 @@
end
def scope &scope
if scope
@scope = scope
- else
+ else
filtered_driver.scope
end
end
def filter *args, &block
@@ -95,14 +96,19 @@
BlockFilter.new self, name, opts, &block
when select = opts.delete(:select)
if opts[:facet] && opts[:facet] != true
opts.merge! values: opts[:facet]
end
- filters = [select].flatten.map{|name| @filters[name] || scope_filter(name)}
+ select = [select] unless select.respond_to?(:each)
+ filters = select.map do |label,filter_name|
+ filter_name ||= label
+ @filters[filter_name] || scope_filter(label,filter_name,label: label)
+ end
SelectFilter.new self, name, filters, opts
- when s = opts.delete(:scope)
- scope_filter( s == true ? name : s, opts )
+ when scope_name = opts.delete(:scope)
+ scope_name = name if scope_name == true
+ scope_filter name, scope_name
else
if opts[:facet] && opts[:facet] != true
opts.merge! values: opts[:facet]
end
ColumnFilter.new self, name, opts
@@ -136,14 +142,14 @@
filter opts.delete(:to){:"to_#{name}"}, opts do |scope, value|
create_driver(scope).less_or_equal(column, value).scope
end
- filter name, :column => column
+ filter name, column: column
end
- def scope_filter name, opts = {}
- BlockFilter.new(self,name, opts){|scope| create_driver(scope).named_scope(name).scope}
+ def scope_filter name, scope_name, opts = {}
+ BlockFilter.new(self, name, opts){|scope| create_driver(scope).named_scope(scope_name).scope}
end
end
end