rares-acts_as_filterable 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml
CHANGED
data/acts_as_filterable.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{acts_as_filterable}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Rob Ares"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-09-01}
|
10
10
|
s.email = %q{rob.ares@gmail.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
"acts_as_filterable.gemspec",
|
23
23
|
"init.rb",
|
24
24
|
"lib/acts_as_filterable.rb",
|
25
|
-
"lib/base.rb",
|
25
|
+
"lib/acts_as_filterable/base.rb",
|
26
26
|
"rails/init.rb",
|
27
27
|
"test/acts_as_filterable_integration_test.rb",
|
28
28
|
"test/test_helper.rb"
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.homepage = %q{http://github.com/rares/acts_as_filterable}
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
33
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.
|
34
|
+
s.rubygems_version = %q{1.3.2}
|
35
35
|
s.summary = %q{TODO}
|
36
36
|
s.test_files = [
|
37
37
|
"test/acts_as_filterable_integration_test.rb",
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
|
41
41
|
if s.respond_to? :specification_version then
|
42
42
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
-
s.specification_version =
|
43
|
+
s.specification_version = 3
|
44
44
|
|
45
45
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
46
|
s.add_runtime_dependency(%q<activerecord>, [">= 1.15.0"])
|
@@ -13,26 +13,26 @@ module ActsAsFilterable
|
|
13
13
|
|
14
14
|
module ClassMethods
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def filter_for_digits(*args)
|
17
|
+
filtered_attributes[:digits] |= args unless args.empty?
|
18
18
|
end
|
19
19
|
|
20
20
|
def filters
|
21
|
-
@filters ||=
|
22
|
-
f =
|
23
|
-
|
24
|
-
f
|
25
|
-
end
|
21
|
+
@filters ||= returning(Hash.new([])) do |f|
|
22
|
+
f[:digits] = /[^\d]*/
|
23
|
+
end.freeze
|
26
24
|
end
|
27
25
|
|
28
|
-
def
|
29
|
-
@
|
26
|
+
def filtered_attributes
|
27
|
+
@filtered_attributes ||= Hash.new []
|
30
28
|
end
|
31
29
|
|
32
30
|
end
|
33
31
|
|
32
|
+
protected
|
33
|
+
|
34
34
|
def apply_filters
|
35
|
-
self.class.
|
35
|
+
self.class.filtered_attributes.each do |key, value|
|
36
36
|
value.each do |attr|
|
37
37
|
apply_filter self.class.filters[key], attr
|
38
38
|
end
|
data/lib/acts_as_filterable.rb
CHANGED
@@ -16,7 +16,7 @@ class ActsAsFilterableIntegrationTest < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
should "know about the types of filters that will be applied to the attributes" do
|
19
|
-
ContactDetail.respond_to?(:
|
19
|
+
ContactDetail.respond_to?(:filtered_attributes).should be(true)
|
20
20
|
end
|
21
21
|
|
22
22
|
should "make it's filters available" do
|
@@ -32,11 +32,11 @@ class ActsAsFilterableIntegrationTest < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
should "freeze the macro collection so it cannot be mutated" do
|
35
|
-
ContactDetail.filters.store(:test, /./).should raise_error
|
35
|
+
lambda { ContactDetail.filters.store(:test, /./) }.should raise_error
|
36
36
|
end
|
37
37
|
|
38
38
|
should "add a macro to filter non-numeric values from string fields" do
|
39
|
-
ContactDetail.respond_to?(:
|
39
|
+
ContactDetail.respond_to?(:filter_for_digits).should be(true)
|
40
40
|
end
|
41
41
|
|
42
42
|
should "be savable with valid data" do
|
@@ -76,7 +76,7 @@ class ActsAsFilterableIntegrationTest < Test::Unit::TestCase
|
|
76
76
|
|
77
77
|
context "with non-character attributes" do
|
78
78
|
setup do
|
79
|
-
ContactDetail.
|
79
|
+
ContactDetail.filter_for_digits :discount
|
80
80
|
end
|
81
81
|
|
82
82
|
should "not raise any errors due to a non-character attribute value" do
|
data/test/test_helper.rb
CHANGED
@@ -5,7 +5,7 @@ require "matchy"
|
|
5
5
|
|
6
6
|
gem "sqlite3-ruby"
|
7
7
|
|
8
|
-
require
|
8
|
+
require "acts_as_filterable"
|
9
9
|
|
10
10
|
ActiveRecord::Base.logger = Logger.new("/tmp/acts_as_filterable.log")
|
11
11
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "/tmp/acts_as_filterable.sqlite")
|
@@ -21,7 +21,7 @@ ActiveRecord::Schema.define do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
class ContactDetail < ActiveRecord::Base
|
24
|
-
|
24
|
+
filter_for_digits :phone_number, :fax_number
|
25
25
|
end
|
26
26
|
|
27
27
|
class Test::Unit::TestCase
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rares-acts_as_filterable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Ares
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -41,7 +41,7 @@ files:
|
|
41
41
|
- acts_as_filterable.gemspec
|
42
42
|
- init.rb
|
43
43
|
- lib/acts_as_filterable.rb
|
44
|
-
- lib/base.rb
|
44
|
+
- lib/acts_as_filterable/base.rb
|
45
45
|
- rails/init.rb
|
46
46
|
- test/acts_as_filterable_integration_test.rb
|
47
47
|
- test/test_helper.rb
|
@@ -69,7 +69,7 @@ requirements: []
|
|
69
69
|
rubyforge_project:
|
70
70
|
rubygems_version: 1.2.0
|
71
71
|
signing_key:
|
72
|
-
specification_version:
|
72
|
+
specification_version: 3
|
73
73
|
summary: TODO
|
74
74
|
test_files:
|
75
75
|
- test/acts_as_filterable_integration_test.rb
|