Skip to content
Browse files

Fix issue with string-based formatters

  • Loading branch information...
1 parent c5fd285 commit 1351051c2e8b871ced43e4fe87a14bb3b6f1cd85 @ernie ernie committed Sep 29, 2010
Showing with 17 additions and 14 deletions.
  1. +3 −0 CHANGELOG
  2. +1 −1 VERSION
  3. +2 −2 lib/meta_search/builder.rb
  4. +8 −8 lib/meta_search/method.rb
  5. +1 −1 lib/meta_search/where.rb
  6. +2 −2 meta_search.gemspec
View
3 CHANGELOG
@@ -1,3 +1,6 @@
+Changes since 0.9.5 (2010-09-28):
+ * Fix issue with formatters supplied s strings
+
Changes since 0.9.4 (2010-09-18):
* Rename check_boxes and collection_check_boxes to checks and
collection_checks. Alias to the old names if not already taken. This
View
2 VERSION
@@ -1 +1 @@
-0.9.5
+0.9.6
View
4 lib/meta_search/builder.rb
@@ -220,7 +220,7 @@ def build_named_method(name)
define_method("#{name}=") do |val|
search_attributes[name] = meth.cast_param(val)
if meth.validate(search_attributes[name])
- return_value = meth.eval(@relation, search_attributes[name])
+ return_value = meth.evaluate(@relation, search_attributes[name])
if return_value.is_a?(ActiveRecord::Relation)
@relation = return_value
else
@@ -242,7 +242,7 @@ def build_attribute_method(attribute, predicate)
search_attributes["#{attribute}_#{predicate}"] = cast_attributes(where.cast || column_type(attribute), val)
if where.validate(search_attributes["#{attribute}_#{predicate}"])
arel_attribute = get_attribute(attribute)
- @relation = where.eval(@relation, arel_attribute, search_attributes["#{attribute}_#{predicate}"])
+ @relation = where.evaluate(@relation, arel_attribute, search_attributes["#{attribute}_#{predicate}"])
end
end
end
View
16 lib/meta_search/method.rb
@@ -65,9 +65,9 @@ module MetaSearch
# the class of your parameters, for instance.
class Method
include Utility
-
+
attr_reader :name, :formatter, :validator, :type
-
+
def initialize(name, opts ={})
raise ArgumentError, "Name parameter required" if name.blank?
@name = name
@@ -86,7 +86,7 @@ def initialize(name, opts ={})
raise ArgumentError, "Invalid validator for #{name}, should be a Proc."
end
end
-
+
# Cast the parameter to the type specified in the Method's <tt>type</tt>
def cast_param(param)
if type.is_a?(Array)
@@ -102,25 +102,25 @@ def cast_param(param)
cast_attributes(type, param)
end
end
-
+
# Evaluate the method in the context of the supplied relation and parameter
- def eval(relation, param)
+ def evaluate(relation, param)
if splat_param?
relation.send(name, *format_param(param))
else
relation.send(name, format_param(param))
end
end
-
+
def splat_param?
!!@splat_param
end
-
+
# Format a parameter for searching using the Method's defined formatter.
def format_param(param)
formatter.call(param)
end
-
+
# Validate the parameter for use in a search using the Method's defined validator.
def validate(param)
validator.call(param)
View
2 lib/meta_search/where.rb
@@ -97,7 +97,7 @@ def validate(param)
end
# Evaluate the Where for the given relation, attribute, and parameter(s)
- def eval(relation, attribute, param)
+ def evaluate(relation, attribute, param)
if splat_param?
relation.where(attribute.send(predicate, *format_param(param)))
else
View
4 meta_search.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{meta_search}
- s.version = "0.9.5"
+ s.version = "0.9.6"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ernie Miller"]
- s.date = %q{2010-09-28}
+ s.date = %q{2010-09-29}
s.description = %q{
Allows simple search forms to be created against an AR3 model
and its associations, has useful view helpers for sort links

0 comments on commit 1351051

Please sign in to comment.
Something went wrong with that request. Please try again.