Permalink
Browse files

Added ransack dependency, moved default ordering for predicates into …

…ransack_ui
  • Loading branch information...
1 parent ff9fa73 commit 3dd34b0cb6bb0aecfc012d1d0341f6b141c1eba9 @ndbroadbent committed Dec 20, 2012
View
@@ -1,9 +1,10 @@
require "ransack_ui/version"
require "ransack_ui/rails/engine"
require "core_ext/enumerable"
-require "ransack"
require "ransack_chronic"
# Require ransack overrides
require 'ransack_ui/adapters/active_record'
Dir.glob(File.expand_path('../ransack_ui/ransack_overrides/**/*.rb', __FILE__)) {|f| require f }
+
+require "ransack"
@@ -1,4 +1,4 @@
- require 'ransack/helpers/form_builder'
+require 'ransack/helpers/form_builder'
module Ransack
module Helpers
@@ -58,6 +58,22 @@ def sort_select(options = {}, html_options = {})
end
end
+ def predicate_keys(options)
+ keys = options[:compounds] ? Predicate.names : Predicate.names.reject {|k| k.match(/_(any|all)$/)}
+ if only = options[:only]
+ if only.respond_to? :call
+ keys = keys.select {|k| only.call(k)}
+ else
+ only = Array.wrap(only).map(&:to_s)
+ # Create compounds hash, e.g. {"eq" => ["eq", "eq_any", "eq_all"], "blank" => ["blank"]}
+ key_groups = keys.inject(Hash.new([])){ |h,k| h[k.sub(/_(any|all)$/, '')] += [k]; h }
+ # Order compounds hash by 'only' keys
+ keys = only.map {|k| key_groups[k] }.flatten.compact
+ end
+ end
+ keys
+ end
+
def predicate_select(options = {}, html_options = {})
options = Ransack.options[:default_predicates] || {} if options.blank?
@@ -154,5 +170,6 @@ def attribute_collection_for_base(base)
nil
end
end
+
end
end
@@ -0,0 +1,13 @@
+require 'ransack/nodes/condition'
+
+module Ransack
+ module Nodes
+ Condition.class_eval do
+ attr_writer :is_default
+
+ def default?
+ @is_default
+ end
+ end
+ end
+end
@@ -0,0 +1,20 @@
+require 'ransack/nodes/grouping'
+
+module Ransack
+ module Nodes
+ Grouping.class_eval do
+
+ def new_condition(opts = {})
+ attrs = opts[:attributes] || 1
+ vals = opts[:values] || 1
+ condition = Condition.new(@context)
+ condition.predicate_name = opts[:predicate] || 'eq'
+ condition.is_default = true
+ attrs.times { condition.build_attribute }
+ vals.times { condition.build_value }
+ condition
+ end
+
+ end
+ end
+end
View
@@ -18,5 +18,6 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
- gem.add_dependency 'ransack_chronic'
+ gem.add_dependency 'ransack_chronic', '>= 1.1.0'
+ gem.add_dependency 'ransack'
end

0 comments on commit 3dd34b0

Please sign in to comment.