redsnow 0.1.2 → 0.1.3

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: 8e802932e6b9f11326595b119e1518d9e23464c3
4
- data.tar.gz: a53782c42fd6fadf4efbfe0aee8071930b793908
3
+ metadata.gz: 4c77d3abeb952177baf63c58d6a73f9e4fec74f9
4
+ data.tar.gz: afa2d73de37d29ffbfa3b18daca644d2047dcef5
5
5
  SHA512:
6
- metadata.gz: 045cc18d064010d0457a93d2fbe1bc0c1864b8d3c517166cced3ba5e355647347c919915707d9e90b58b61de216b84403409ce05be7eb0b4214ff0c027e895d2
7
- data.tar.gz: 9061c9bd3b8796561eb489a4afe401c6bb34f784c49deed7493e7f6ed7f7111043da4fbba3871073972e25cc8714f82efdcb144ec8b28481e18c26a950194a5e
6
+ metadata.gz: d43c806fe110d5829c630fa98dd15e5e89f9d30a4ea92186d3ca432d7aa4ff3675769026377ce74c08c528eaf24192a3d4d7c872d91fe19643df4a16951013c5
7
+ data.tar.gz: f7873c7fa6a23cbad92bbc387a4525eb963ddf9c15403388b9bb6eeb4e17e8d32fd14010018419136c22f1876b7fb779cd36a71d3040947538507a87f9152d4a
data/CHANGELOG.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Changelog
2
+ - 0.1.3 - Add Element Reference method to KeyValueCollection class [PR#17](https://github.com/apiaryio/redsnow/pull/17)
2
3
  - 0.1.2 - Fix collection of resources inside ResourceGroup [PR#13](https://github.com/apiaryio/redsnow/pull/13)
3
4
  - 0.1.1 - Add bundler to dependency
4
5
  - 0.1.0 - Snow Crash updated to [0.12.1](https://github.com/apiaryio/snowcrash/releases/tag/v0.12.1)
@@ -45,6 +45,15 @@ module RedSnow
45
45
 
46
46
  attr_accessor :collection
47
47
 
48
+ # Retrieves the value of the collection item by its key
49
+ #
50
+ # @param key [String] Name of the item key to retrieve
51
+ # @return [NilClass] if the collection does not have an item with the key
52
+ # @return [String] if the collection has an item with the key
53
+ def [] key
54
+ return nil if @collection.nil?
55
+ return_item_value key
56
+ end
48
57
  # Filter collection keys
49
58
  #
50
59
  # @return [Array<Hash>] collection without ignored keys
@@ -52,6 +61,14 @@ module RedSnow
52
61
  return @collection if ignore_keys.blank?
53
62
  @collection.select { |kv_item| !ignore_keys.include?(kv_item.keys.first) }
54
63
  end
64
+ private
65
+ def return_item_value key
66
+ item = get_item(key.to_s)
67
+ item.nil? ? nil : item[:value]
68
+ end
69
+ def get_item key
70
+ @collection.select{|item| item[:name].downcase == key.downcase }.first
71
+ end
55
72
  end
56
73
 
57
74
  # Metadata collection Blueprint AST node
@@ -1,4 +1,4 @@
1
1
  module RedSnow
2
2
  # Gem version
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
data/test/redsnow_test.rb CHANGED
@@ -134,7 +134,8 @@ class RedSnowParsingTest < Test::Unit::TestCase
134
134
  assert_equal "Hello World\n", @resource.model.body
135
135
  assert_equal 1, @resource.model.headers.collection.count
136
136
  assert_equal "Content-Type", @resource.model.headers.collection[0][:name]
137
- assert_equal "text/plain", @resource.model.headers.collection[0][:value]
137
+ assert_equal "text/plain", @resource.model.headers['content-type']
138
+ assert_equal "text/plain", @resource.model.headers['Content-Type']
138
139
  end
139
140
 
140
141
  should "have actions" do
@@ -158,21 +159,30 @@ class RedSnowParsingTest < Test::Unit::TestCase
158
159
  STR
159
160
 
160
161
  @result = RedSnow.parse(source.unindent)
161
- @metadata = @result.ast.metadata.collection
162
+ @metadata = @result.ast.metadata
163
+ @collection = @metadata.collection
162
164
  end
163
165
 
164
166
  should "have metadata" do
165
- assert_equal 'FORMAT', @metadata[0][:name]
166
- assert_equal '1A', @metadata[0][:value]
167
+ assert_equal 'FORMAT', @collection[0][:name]
168
+ assert_equal '1A', @collection[0][:value]
167
169
 
168
- assert_equal 'A', @metadata[1][:name]
169
- assert_equal '1', @metadata[1][:value]
170
+ assert_equal 'A', @collection[1][:name]
171
+ assert_equal '1', @collection[1][:value]
170
172
 
171
- assert_equal 'B', @metadata[2][:name]
172
- assert_equal '2', @metadata[2][:value]
173
+ assert_equal 'B', @collection[2][:name]
174
+ assert_equal '2', @collection[2][:value]
173
175
 
174
- assert_equal 'C', @metadata[3][:name]
175
- assert_equal '3', @metadata[3][:value]
176
+ assert_equal 'C', @collection[3][:name]
177
+ assert_equal '3', @collection[3][:value]
178
+ end
179
+
180
+ should "return metadata values by element reference method" do
181
+ assert_equal '1A', @metadata['FORMAT']
182
+ assert_equal '1', @metadata['A']
183
+ assert_equal '2', @metadata['B']
184
+ assert_equal '3', @metadata['C']
185
+ assert_equal nil, @metadata['D']
176
186
  end
177
187
  end
178
188
 
@@ -295,9 +305,9 @@ class RedSnowParsingTest < Test::Unit::TestCase
295
305
  assert_equal "201", @examples[0].responses[0].name
296
306
  assert_equal "Unable to create note", @examples[1].requests[0].name
297
307
  assert_equal "Content-Type", @examples[1].requests[0].headers.collection[0][:name]
298
- assert_equal "application/json", @examples[1].requests[0].headers.collection[0][:value]
308
+ assert_equal "application/json", @examples[1].requests[0].headers['content-type']
299
309
  assert_equal "Prefer", @examples[1].requests[0].headers.collection[1][:name]
300
- assert_equal "testing", @examples[1].requests[0].headers.collection[1][:value]
310
+ assert_equal "testing", @examples[1].requests[0].headers['prefer']
301
311
  assert_equal '{ "ti": "Buy cheese and bread for breakfast." }' + "\n", @examples[1].requests[0].body
302
312
  assert_equal "500", @examples[1].responses[0].name
303
313
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redsnow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ladislav Prskavec
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-22 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi