Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix issue with string-based formatters

  • Loading branch information...
commit 1351051c2e8b871ced43e4fe87a14bb3b6f1cd85 1 parent c5fd285
Ernie Miller ernie authored
3  CHANGELOG
... ... @@ -1,3 +1,6 @@
  1 +Changes since 0.9.5 (2010-09-28):
  2 + * Fix issue with formatters supplied s strings
  3 +
1 4 Changes since 0.9.4 (2010-09-18):
2 5 * Rename check_boxes and collection_check_boxes to checks and
3 6 collection_checks. Alias to the old names if not already taken. This
2  VERSION
... ... @@ -1 +1 @@
1   -0.9.5
  1 +0.9.6
4 lib/meta_search/builder.rb
@@ -220,7 +220,7 @@ def build_named_method(name)
220 220 define_method("#{name}=") do |val|
221 221 search_attributes[name] = meth.cast_param(val)
222 222 if meth.validate(search_attributes[name])
223   - return_value = meth.eval(@relation, search_attributes[name])
  223 + return_value = meth.evaluate(@relation, search_attributes[name])
224 224 if return_value.is_a?(ActiveRecord::Relation)
225 225 @relation = return_value
226 226 else
@@ -242,7 +242,7 @@ def build_attribute_method(attribute, predicate)
242 242 search_attributes["#{attribute}_#{predicate}"] = cast_attributes(where.cast || column_type(attribute), val)
243 243 if where.validate(search_attributes["#{attribute}_#{predicate}"])
244 244 arel_attribute = get_attribute(attribute)
245   - @relation = where.eval(@relation, arel_attribute, search_attributes["#{attribute}_#{predicate}"])
  245 + @relation = where.evaluate(@relation, arel_attribute, search_attributes["#{attribute}_#{predicate}"])
246 246 end
247 247 end
248 248 end
16 lib/meta_search/method.rb
@@ -65,9 +65,9 @@ module MetaSearch
65 65 # the class of your parameters, for instance.
66 66 class Method
67 67 include Utility
68   -
  68 +
69 69 attr_reader :name, :formatter, :validator, :type
70   -
  70 +
71 71 def initialize(name, opts ={})
72 72 raise ArgumentError, "Name parameter required" if name.blank?
73 73 @name = name
@@ -86,7 +86,7 @@ def initialize(name, opts ={})
86 86 raise ArgumentError, "Invalid validator for #{name}, should be a Proc."
87 87 end
88 88 end
89   -
  89 +
90 90 # Cast the parameter to the type specified in the Method's <tt>type</tt>
91 91 def cast_param(param)
92 92 if type.is_a?(Array)
@@ -102,25 +102,25 @@ def cast_param(param)
102 102 cast_attributes(type, param)
103 103 end
104 104 end
105   -
  105 +
106 106 # Evaluate the method in the context of the supplied relation and parameter
107   - def eval(relation, param)
  107 + def evaluate(relation, param)
108 108 if splat_param?
109 109 relation.send(name, *format_param(param))
110 110 else
111 111 relation.send(name, format_param(param))
112 112 end
113 113 end
114   -
  114 +
115 115 def splat_param?
116 116 !!@splat_param
117 117 end
118   -
  118 +
119 119 # Format a parameter for searching using the Method's defined formatter.
120 120 def format_param(param)
121 121 formatter.call(param)
122 122 end
123   -
  123 +
124 124 # Validate the parameter for use in a search using the Method's defined validator.
125 125 def validate(param)
126 126 validator.call(param)
2  lib/meta_search/where.rb
@@ -97,7 +97,7 @@ def validate(param)
97 97 end
98 98
99 99 # Evaluate the Where for the given relation, attribute, and parameter(s)
100   - def eval(relation, attribute, param)
  100 + def evaluate(relation, attribute, param)
101 101 if splat_param?
102 102 relation.where(attribute.send(predicate, *format_param(param)))
103 103 else
4 meta_search.gemspec
@@ -5,11 +5,11 @@
5 5
6 6 Gem::Specification.new do |s|
7 7 s.name = %q{meta_search}
8   - s.version = "0.9.5"
  8 + s.version = "0.9.6"
9 9
10 10 s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11 11 s.authors = ["Ernie Miller"]
12   - s.date = %q{2010-09-28}
  12 + s.date = %q{2010-09-29}
13 13 s.description = %q{
14 14 Allows simple search forms to be created against an AR3 model
15 15 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.