machine_tag 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,8 +46,8 @@ module MachineTag
46
46
  # @param block [Proc] the optional block to preprocess elements before inserting them
47
47
  #
48
48
  def initialize(enum = nil, &block)
49
- @plain_tags = ::Set.new
50
- @machine_tags = ::Set.new
49
+ @plain_tags = ::Set[]
50
+ @machine_tags = ::Set[]
51
51
  @tags_by_namespace = {}
52
52
  @tags_by_namespace_and_predicate = {}
53
53
  super
@@ -65,9 +65,9 @@ module MachineTag
65
65
 
66
66
  if tag.machine_tag?
67
67
  @machine_tags << tag
68
- @tags_by_namespace[tag.namespace] ||= ::Set.new
68
+ @tags_by_namespace[tag.namespace] ||= ::Set[]
69
69
  @tags_by_namespace[tag.namespace] << tag
70
- @tags_by_namespace_and_predicate[tag.namespace_and_predicate] ||= ::Set.new
70
+ @tags_by_namespace_and_predicate[tag.namespace_and_predicate] ||= ::Set[]
71
71
  @tags_by_namespace_and_predicate[tag.namespace_and_predicate] << tag
72
72
  else
73
73
  @plain_tags << tag
@@ -116,20 +116,20 @@ module MachineTag
116
116
  namespace = namespace_or_namespace_and_predicate
117
117
 
118
118
  unless predicate
119
- @tags_by_namespace[namespace]
119
+ @tags_by_namespace[namespace] || Set[]
120
120
  else
121
121
  case predicate
122
122
  when Regexp
123
123
  ::Set.new @tags_by_namespace[namespace].select { |machine_tag| machine_tag.predicate =~ predicate }
124
124
  else
125
125
  raise ArgumentError, "Invalid machine tag predicate: #{predicate.inspect}" unless predicate =~ /^#{PREFIX}$/
126
- @tags_by_namespace_and_predicate["#{namespace}:#{predicate}"]
126
+ @tags_by_namespace_and_predicate["#{namespace}:#{predicate}"] || Set[]
127
127
  end
128
128
  end
129
129
  elsif namespace_or_namespace_and_predicate =~ /^#{NAMESPACE_AND_PREDICATE}$/
130
130
  namespace_and_predicate = namespace_or_namespace_and_predicate
131
131
  raise ArgumentError, "Separate predicate passed with namespace and predicate: #{namespace_and_predicate.inspect}, #{predicate.inspect}" if predicate
132
- @tags_by_namespace_and_predicate[namespace_and_predicate]
132
+ @tags_by_namespace_and_predicate[namespace_and_predicate] || Set[]
133
133
  else
134
134
  raise ArgumentError, "Invalid machine tag namespace and/or predicate: #{namespace_or_namespace_and_predicate.inspect}, #{predicate.inspect}"
135
135
  end
@@ -26,5 +26,5 @@
26
26
  module MachineTag
27
27
  # The version of this library.
28
28
  #
29
- VERSION = "1.1.2"
29
+ VERSION = "1.1.3"
30
30
  end
@@ -29,7 +29,7 @@ describe MachineTag::Set do
29
29
  end
30
30
 
31
31
  describe '#add' do
32
- let(:tags) { MachineTag::Set.new }
32
+ let(:tags) { MachineTag::Set[] }
33
33
 
34
34
  it 'should add strings' do
35
35
  tags << 'a'
@@ -76,6 +76,38 @@ describe MachineTag::Set do
76
76
  tags[/^[abc]/, /^(cc|ee)$/].should eq Set['aa:cc=1', 'bb:cc=3', 'cc:ee=5']
77
77
  end
78
78
 
79
+ it 'should return an empty set with a String for namespace and no predicate' do
80
+ tags['xx'].should eq Set[]
81
+ end
82
+
83
+ it 'should return an empty set with a String for namespace and predicate' do
84
+ tags['aa', 'xx'].should eq Set[]
85
+ end
86
+
87
+ it 'should return an empty set with a String for namespace and predicate as one argument' do
88
+ tags['aa:xx'].should eq Set[]
89
+ end
90
+
91
+ it 'should return an empty set with a Regexp for namespace and no predicate' do
92
+ tags[/^x/].should eq Set[]
93
+ end
94
+
95
+ it 'should return an empty set with a Regexp for namespace and predicate as one argument' do
96
+ tags[/^.x:y.$/].should eq Set[]
97
+ end
98
+
99
+ it 'should return an empty set with a Regexp for namespace and a String for predicate' do
100
+ tags[/^a/, 'xx'].should eq Set[]
101
+ end
102
+
103
+ it 'should return an empty set with a String for namespace and Regexp for predicate' do
104
+ tags['cc', /^x/].should eq Set[]
105
+ end
106
+
107
+ it 'should return an empty set with a Regexp for namespace and predicate' do
108
+ tags[/^a/, /^x/].should eq Set[]
109
+ end
110
+
79
111
  it 'should not retrieve with an invalid predicate' do
80
112
  expect do
81
113
  tags['a', '!']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machine_tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-18 00:00:00.000000000 Z
12
+ date: 2014-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler