context-filters 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72b337b95267065dd3e8871ef42ad22fd7311322
4
- data.tar.gz: cc77744a86f4e924bd30170faf0d412c58110a4d
3
+ metadata.gz: 9f1809572fcd86c5f8ee99f43c956fa4ebbba43b
4
+ data.tar.gz: a4c0c942c34bcabfb2193b2d8f59cb2fa2bcf23e
5
5
  SHA512:
6
- metadata.gz: 21860acb146a459728f2fe625f0730f1d85e9c97e4e96baef3cf1ce194b444f238d6adedc903b23339bff2711e17fe96ec3fb1d2774127242c09e7d779aa368f
7
- data.tar.gz: 2dfa1be389f8301ec671bfab1c55e922472d5ba825a68ec6c5849a99d6fd22dda1c9329c2baecec5ae30ebd79318887e2de92791e57cda01abccac978abe10b4
6
+ metadata.gz: 5b0f70e4be2fbf8c869f8be48a9ac20d9051b7c757d1cdad9f822e5242ab7ef432be7ef117a073bd2cae76a7ee2337f55c7ba157affe239e3f46420b63e09fe9
7
+ data.tar.gz: 1274b880b437e254e86c98027a30efa26175ae57758d135b786a0b5383d3d434cdc70b500c23a76c36eed0abbad5ef17b87423396d6c10cf55a94f98a08ea5a9
@@ -12,7 +12,7 @@ class ContextFilters::GlobalContext
12
12
 
13
13
  # @return [Array] the context stack
14
14
  # @api private
15
- attr_reader :context
15
+ attr_reader :context_stack
16
16
 
17
17
  # @return [PriorityFilters] shared list of filters
18
18
  # @api private
@@ -26,15 +26,15 @@ class ContextFilters::GlobalContext
26
26
  #
27
27
  # @param priority_filters [Array,PriorityFilters] when PriorityFilters - uses it for priority_filters
28
28
  # otherwise - initializes new priority_filters with it
29
- # @param context [Array] parents context, duplicates to initialize own context
30
- # @param options [Object] new context, ads it to current context
29
+ # @param context_stack [Array] parents context_stack, duplicates to initialize own context_stack
30
+ # @param options [Object] new context, ads it to context_stack
31
31
  #
32
- def initialize(priority_filters = nil, context = [], options = nil)
32
+ def initialize(priority_filters = nil, context_stack = [], options = nil)
33
33
  if ContextFilters::PriorityFilters === priority_filters
34
34
  then @priority_filters = priority_filters
35
35
  else @priority_filters = ContextFilters::PriorityFilters.new(priority_filters)
36
36
  end
37
- @context = context.dup + [options]
37
+ @context_stack = context_stack.dup + [options]
38
38
  end
39
39
 
40
40
  # defines new filter for given +priority+ and +options+
@@ -51,12 +51,13 @@ class ContextFilters::GlobalContext
51
51
  # @param options [Object] options to start new context
52
52
  # @param block [Proc] code block that will enable filtering for the given +options+
53
53
  # @yield [GlobalContext] the new context
54
- def in_context(options, &block)
55
- self.class.new(@priority_filters, @context, options).tap(&block)
54
+ def context(options, &block)
55
+ self.class.new(@priority_filters, @context_stack, options).tap(&block)
56
56
  end
57
57
 
58
- # evaluates all matching filters for given context, allows to do extra
58
+ # evaluates all matching filters for given context_stack, allows to do extra
59
59
  # work for +priority.nil?+ or on the end of the priorities,
60
+ #
60
61
  # @param method [Proc] the method to evaluate with filters matching current context
61
62
  # @yield on first +priority.nil?+ or on the end when none
62
63
  def evaluate_filters(target, method)
@@ -64,7 +65,7 @@ class ContextFilters::GlobalContext
64
65
 
65
66
  @priority_filters.each do |priority, filters|
66
67
 
67
- @context.each { |options| filters.apply(target, method, options) }
68
+ @context_stack.each { |options| filters.apply(target, method, options) }
68
69
 
69
70
  if priority.nil? && block_given? && !local_called
70
71
  yield
@@ -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.2"
4
+ VERSION = "0.10.0"
5
5
  end
@@ -26,7 +26,7 @@ describe ContextFilters::Context do
26
26
  end
27
27
 
28
28
  it "does apply global filters" do
29
- subject.context << :a
29
+ subject.context_stack << :a
30
30
  subject.filter(nil, :b) { true }
31
31
  subject.priority_filters.to_a[0][1].expects(:apply).once.with(filter_test_subject, :change, nil)
32
32
  subject.priority_filters.to_a[0][1].expects(:apply).once.with(filter_test_subject, :change, :a)
@@ -23,7 +23,7 @@ describe ContextFilters::GlobalContext do
23
23
  it "sets up initial variables" do
24
24
  subject.priority_filters.must_be_kind_of ContextFilters::PriorityFilters
25
25
  subject.priority_filters.must_be_empty
26
- subject.context.must_equal([nil])
26
+ subject.context_stack.must_equal([nil])
27
27
  end
28
28
 
29
29
  end #initialize
@@ -42,7 +42,7 @@ describe ContextFilters::GlobalContext do
42
42
 
43
43
  it "does apply filters" do
44
44
  method = Proc.new{}
45
- subject.context << :a
45
+ subject.context_stack << :a
46
46
  subject.filter(nil, :b) { true }
47
47
  subject.priority_filters.to_a[0][1].expects(:apply).once.with(filter_test_subject, :change, nil)
48
48
  subject.priority_filters.to_a[0][1].expects(:apply).once.with(filter_test_subject, :change, :a)
@@ -61,7 +61,7 @@ describe ContextFilters::GlobalContext do
61
61
  it "does apply targeted filters in sub context" do
62
62
  addition = Proc.new { |value| value+1 }
63
63
  multiplication = Proc.new { |value| value*3 }
64
- subject.context << { :a => 1 }
64
+ subject.context_stack << { :a => 1 }
65
65
  subject.filter(nil, {:a => 1, :target => filter_test_subject}, &addition)
66
66
  subject.filter(nil, {:a => 1, :target => nil}, &multiplication)
67
67
  subject.evaluate_filters(filter_test_subject, :change)
@@ -73,23 +73,23 @@ describe ContextFilters::GlobalContext do
73
73
  describe "#group" do
74
74
 
75
75
  it "nests" do
76
- subject.in_context(:a) do |test_a|
76
+ subject.context(:a) do |test_a|
77
77
 
78
78
  test_a.must_be_kind_of ContextFilters::GlobalContext
79
79
  test_a.priority_filters.object_id.must_equal(subject.priority_filters.object_id)
80
- test_a.context.object_id.wont_equal(subject.context.object_id)
81
- test_a.context.must_equal([nil, :a])
80
+ test_a.context_stack.object_id.wont_equal(subject.context_stack.object_id)
81
+ test_a.context_stack.must_equal([nil, :a])
82
82
 
83
- test_a.in_context(:b) do |test_b|
83
+ test_a.context(:b) do |test_b|
84
84
  test_b.must_be_kind_of ContextFilters::GlobalContext
85
85
  test_b.priority_filters.object_id.must_equal(test_a.priority_filters.object_id)
86
- test_b.context.object_id.wont_equal(test_a.context.object_id)
87
- test_b.context.must_equal([nil, :a, :b])
86
+ test_b.context_stack.object_id.wont_equal(test_a.context_stack.object_id)
87
+ test_b.context_stack.must_equal([nil, :a, :b])
88
88
  end
89
89
 
90
- test_a.context.must_equal([nil, :a])
90
+ test_a.context_stack.must_equal([nil, :a])
91
91
  end
92
- subject.context.must_equal([nil])
92
+ subject.context_stack.must_equal([nil])
93
93
  end
94
94
 
95
95
  end #group
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.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Papis
@@ -143,8 +143,8 @@ test_files:
143
143
  - test/test_helper.rb
144
144
  - test/context-filters/priority_filters_test.rb
145
145
  - test/context-filters/local_context_test.rb
146
- - test/context-filters/context_test.rb
147
- - test/context-filters/global_context_test.rb
148
146
  - test/context-filters/filter_test_subject.rb
149
147
  - test/context-filters/filters_test.rb
148
+ - test/context-filters/global_context_test.rb
149
+ - test/context-filters/context_test.rb
150
150
  has_rdoc: