redfish_client 0.2.2 → 0.2.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
  SHA256:
3
- metadata.gz: a0d5afda19f44e42b56223398478a6542c3001449eaa268a554adf53be44f169
4
- data.tar.gz: 3a37535bab3af7cc4457c9aed9b9718da7b27922b2a70da58938d376576df10d
3
+ metadata.gz: 207554e7443e5ebe22eb6f2c76561697a52ff0bdc133cfa21eeb56537100cfe6
4
+ data.tar.gz: 0433356121c5f822036f311aa9ae679d01f067b9ecc9789574b3b476b542b540
5
5
  SHA512:
6
- metadata.gz: 23cf48798d7952009e20c450f9fcc22aa6116902ef01c6d2446c1c4f35ea2ed2ec4a9db6f817583dec42fb09221ff3764b72577e05fe9327bc92ffc1d4890f37
7
- data.tar.gz: 83517b7ef8012c483e4b73afbe456e618e0ebf614d5d741ba42f2bf5fbf7ca0cdde35badb3e56512fc0a786503c84df424d97e2d617160105e58eafbeb534d46
6
+ metadata.gz: a2ddcc580f63812be3b07ffed4da2cc5cffb01b52b44c7030b8388fc87fdcc6054ba32b3855ee94247ab500e1f3d69c5547e2544c9aff7b4a7ac7ff3f18a4a17
7
+ data.tar.gz: 541d959834877c466f432962b250d9d02f98ce783ac6e38f3584e636a0a2271e6f3bb4520f0bd49e3991a2d8ec90b02e19ba2a2c2ee41804aa5a89283d704def
@@ -1,3 +1,4 @@
1
1
  plugins:
2
2
  rubocop:
3
3
  enabled: true
4
+ channel: rubocop-0-54
@@ -9,6 +9,10 @@ AllCops:
9
9
  Layout/MultilineOperationIndentation:
10
10
  EnforcedStyle: indented
11
11
 
12
+ Style/MethodMissing:
13
+ Exclude:
14
+ - lib/redfish_client/resource.rb
15
+
12
16
  Style/StringLiterals:
13
17
  EnforcedStyle: double_quotes
14
18
 
@@ -64,20 +64,32 @@ module RedfishClient
64
64
  # Members array. This means that `res["Members"][3]` can be shortened into
65
65
  # `res[3]`.
66
66
  #
67
- # Accessing non-existent or indexing non-collection resource key will
68
- # raise `KeyError`. Accessing invalid index will raise `IndexError`.
67
+ # Indexing non-collection resource key will # raise `KeyError`.
69
68
  #
70
69
  # @param attr [String, Integer] key or index for accessing data
71
- # @return associated value
70
+ # @return associated value or `nil` if attr is missing
72
71
  def [](attr)
73
72
  if attr.is_a?(Integer)
74
73
  raise(KeyError, "Not a collection.") unless key?("Members")
75
- cache("Members").fetch(attr)
74
+ cache("Members")[attr]
76
75
  else
77
76
  cache(attr)
78
77
  end
79
78
  end
80
79
 
80
+ # Safely access nested resource content.
81
+ #
82
+ # This function is an equivalent of safe navigation operator that can be
83
+ # used with arbitrary keys.
84
+ #
85
+ # Calling `res.dig("a", "b", "c")` is equivalent to `res.a&.b&.c` and
86
+ # `res["a"] && res["a"]["b"] && res["a"]["b"]["c"]`.
87
+ # @params keys [Array<Symbol, String>] sequence of keys to access
88
+ # @return associated value or `nil` if any key is missing
89
+ def dig(*keys)
90
+ keys.reduce(self) { |a, k| a.nil? ? nil : a[k] }
91
+ end
92
+
81
93
  # Test if resource contains required key.
82
94
  #
83
95
  # @param name [String, Symbol] key name to test
@@ -88,12 +100,9 @@ module RedfishClient
88
100
 
89
101
  # Convenience access for resource data.
90
102
  #
91
- # Calling `resource.Value` is exactly the same as `resource["Value"]`. The
92
- # only difference is that accessing non-existent field will raise
93
- # NoMethodError instead of KeyError as `[]` method does.
94
- def method_missing(symbol, *args, &block)
95
- name = symbol.to_s
96
- key?(name) ? self[name] : super
103
+ # Calling `resource.Value` is exactly the same as `resource["Value"]`.
104
+ def method_missing(symbol, *_args, &_block)
105
+ self[symbol.to_s]
97
106
  end
98
107
 
99
108
  def respond_to_missing?(symbol, include_private = false)
@@ -187,10 +196,12 @@ module RedfishClient
187
196
  end
188
197
 
189
198
  def cache(name)
190
- @cache[name] ||= build_resource(@content.fetch(name))
199
+ @cache[name] ||= build_resource(@content[name])
191
200
  end
192
201
 
193
202
  def build_resource(data)
203
+ return nil if data.nil?
204
+
194
205
  case data
195
206
  when Hash then build_hash_resource(data)
196
207
  when Array then data.collect { |d| build_resource(d) }
@@ -204,6 +215,8 @@ module RedfishClient
204
215
  else
205
216
  Resource.new(@connector, content: data)
206
217
  end
218
+ rescue NoResource
219
+ nil
207
220
  end
208
221
  end
209
222
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RedfishClient
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
@@ -36,6 +36,6 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "rspec", ">= 3.7"
37
37
  spec.add_development_dependency "simplecov"
38
38
  spec.add_development_dependency "yard"
39
- spec.add_development_dependency "rubocop"
39
+ spec.add_development_dependency "rubocop", "~> 0.54.0"
40
40
  spec.add_development_dependency "pry"
41
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redfish_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadej Borovšak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 0.54.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 0.54.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: pry
113
113
  requirement: !ruby/object:Gem::Requirement