context-filters 0.9.1 → 0.9.2
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72b337b95267065dd3e8871ef42ad22fd7311322
|
4
|
+
data.tar.gz: cc77744a86f4e924bd30170faf0d412c58110a4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21860acb146a459728f2fe625f0730f1d85e9c97e4e96baef3cf1ce194b444f238d6adedc903b23339bff2711e17fe96ec3fb1d2774127242c09e7d779aa368f
|
7
|
+
data.tar.gz: 2dfa1be389f8301ec671bfab1c55e922472d5ba825a68ec6c5849a99d6fd22dda1c9329c2baecec5ae30ebd79318887e2de92791e57cda01abccac978abe10b4
|
@@ -63,8 +63,16 @@ class ContextFilters::Filters
|
|
63
63
|
# @param options [Object] a filter for selecting matching blocks
|
64
64
|
def select_filters(target, options)
|
65
65
|
found = @filters.fetch(options, [])
|
66
|
-
if
|
67
|
-
|
66
|
+
if
|
67
|
+
Hash === options || options.nil?
|
68
|
+
then
|
69
|
+
options ||={}
|
70
|
+
options.merge!(:target => target)
|
71
|
+
found +=
|
72
|
+
# can not @filters.fetch(options, []) to allow filters provide custom ==()
|
73
|
+
@filters.select do |filter_options, filters|
|
74
|
+
options == filter_options
|
75
|
+
end.map(&:last).flatten
|
68
76
|
end
|
69
77
|
found
|
70
78
|
end
|
@@ -5,11 +5,18 @@ See the file LICENSE for copying permission.
|
|
5
5
|
=end
|
6
6
|
|
7
7
|
class FilterTestSubject
|
8
|
-
attr_accessor :value
|
8
|
+
attr_accessor :value, :initial_value
|
9
9
|
def initialize(value)
|
10
10
|
@value = value
|
11
|
+
@initial_value = value
|
11
12
|
end
|
12
13
|
def change(&block)
|
13
14
|
@value = block.call(@value)
|
14
15
|
end
|
16
|
+
def ==(other)
|
17
|
+
if self.class === other
|
18
|
+
then self.initial_value == other.initial_value
|
19
|
+
else self.initial_value == other
|
20
|
+
end
|
21
|
+
end
|
15
22
|
end
|
@@ -102,6 +102,48 @@ describe ContextFilters::Filters do
|
|
102
102
|
apply_test_subject.value.must_equal("dont test me")
|
103
103
|
end
|
104
104
|
|
105
|
+
it "applies only one target filter by value" do
|
106
|
+
subject.store({x: 1, target: "test me"}) { |value| "dont #{value}" }
|
107
|
+
subject.store({x: 2, target: nil}) { |value| "#{value} now" }
|
108
|
+
|
109
|
+
subject.apply(apply_test_subject, :change, {x: 1})
|
110
|
+
subject.apply(apply_test_subject, :change, {x: 2})
|
111
|
+
|
112
|
+
apply_test_subject.value.must_equal("dont test me")
|
113
|
+
end
|
114
|
+
|
105
115
|
end #apply
|
106
116
|
|
117
|
+
describe "#select_filters" do
|
118
|
+
|
119
|
+
let(:apply_test_subject) do
|
120
|
+
FilterTestSubject.new("test me")
|
121
|
+
end
|
122
|
+
|
123
|
+
it "selects non target filters" do
|
124
|
+
change_method1 = Proc.new {}
|
125
|
+
change_method2 = Proc.new {}
|
126
|
+
subject.store({x: 1}, &change_method1)
|
127
|
+
subject.store({x: 2}, &change_method2)
|
128
|
+
subject.select_filters(apply_test_subject, {x: 1}).must_equal([change_method1])
|
129
|
+
end
|
130
|
+
|
131
|
+
it "selects target filters" do
|
132
|
+
change_method1 = Proc.new {}
|
133
|
+
change_method2 = Proc.new {}
|
134
|
+
subject.store({x: 1, target: apply_test_subject}, &change_method1)
|
135
|
+
subject.store({x: 2, target: apply_test_subject}, &change_method2)
|
136
|
+
subject.select_filters(apply_test_subject, {x: 2}).must_equal([change_method2])
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
it "selects target filters by value" do
|
141
|
+
change_method1 = Proc.new {}
|
142
|
+
change_method2 = Proc.new {}
|
143
|
+
subject.store({x: 1, target: apply_test_subject.initial_value}, &change_method1)
|
144
|
+
subject.store({x: 2, target: apply_test_subject.initial_value}, &change_method2)
|
145
|
+
subject.select_filters(apply_test_subject, {x: 2}).must_equal([change_method2])
|
146
|
+
end
|
147
|
+
|
148
|
+
end #select_filters
|
107
149
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: context-filters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Papis
|
@@ -141,10 +141,10 @@ specification_version: 4
|
|
141
141
|
summary: Generic support for filters applied in context
|
142
142
|
test_files:
|
143
143
|
- test/test_helper.rb
|
144
|
-
- test/context-filters/filter_test_subject.rb
|
145
144
|
- test/context-filters/priority_filters_test.rb
|
146
145
|
- test/context-filters/local_context_test.rb
|
147
146
|
- test/context-filters/context_test.rb
|
148
|
-
- test/context-filters/filters_test.rb
|
149
147
|
- test/context-filters/global_context_test.rb
|
148
|
+
- test/context-filters/filter_test_subject.rb
|
149
|
+
- test/context-filters/filters_test.rb
|
150
150
|
has_rdoc:
|