Skip to content

Commit 04408e6

Browse files
committed
Merge branch 'master' of github.com:infinitered/rmq
2 parents a17320b + b69ebd4 commit 04408e6

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

motion/ruby_motion_query/tags.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ def has_tag? tag
4949
false # tag doesn't exist if we got here
5050
end
5151

52+
def tags(key=nil)
53+
tags = {}
54+
selected.each do |view|
55+
view.rmq_data.tags.each do |tag, data|
56+
tags[tag] ||= []
57+
tags[tag] << data
58+
end
59+
end
60+
tags = tags.inject({}) do |hash,(k,v)|
61+
hash[k] = v.length == 1 ? v.first : v
62+
hash
63+
end
64+
65+
if key
66+
tags[key]
67+
else
68+
tags
69+
end
70+
end
71+
5272
# See /motion/data.rb for the rest of the tag stuff
5373

5474
end

spec/tags.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,22 @@
7474
end
7575
end
7676

77+
it 'should return the tags for the selection' do
78+
@vc.rmq.append(UIView).tag(data: "some-data")
79+
@vc.rmq.append(UIView).tag(other_data: "other-data")
80+
@vc.rmq.all.tags.should == { data: "some-data", other_data: "other-data" }
81+
end
82+
83+
it 'should be able to return tag data' do
84+
@vc.rmq.append(UIView).tag(data: "some-data").tap do |q|
85+
q.tags(:data).should == "some-data"
86+
end
87+
end
88+
89+
it 'should return an array of data if there are duplicate tags in the selection' do
90+
@vc.rmq.append(UIView).tag(data: "some-data")
91+
@vc.rmq.append(UIView).tag(data: "other-data")
92+
@vc.rmq.all.tags(:data).should == ["some-data", "other-data"]
93+
end
94+
7795
end

0 commit comments

Comments
 (0)