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: dbd686f4da29b6833e989c2fbf4511bf23d99c2b
4
- data.tar.gz: ed9ca9da7754db99621a9e12737b6f593107ab11
3
+ metadata.gz: 72b337b95267065dd3e8871ef42ad22fd7311322
4
+ data.tar.gz: cc77744a86f4e924bd30170faf0d412c58110a4d
5
5
  SHA512:
6
- metadata.gz: 1b253abc8dfbd195feb542a6441d0ab977aff2e7b1de80aa0152158de59218525438078280496a979231e479713779d0d28d015b3299288cf1a3387d1f1a995d
7
- data.tar.gz: e91836fa6d5a557b96b019769ddacf8b9030942c9766f24ce5cf9ec619c2dd5038c403af9110f0c3f376062c673930e678050a2a517fb1aef3de10f71ae026b2
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 Hash === options || options.nil?
67
- then found += @filters.fetch((options||{}).merge(:target => target), [])
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
@@ -1,5 +1,5 @@
1
1
  # Build command text based on multiple filters
2
2
  class ContextFilters
3
3
  # version of the context-filters gem
4
- VERSION = "0.9.1"
4
+ VERSION = "0.9.2"
5
5
  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.1
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: