cmis-ruby 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98f7dbcd1d1ddca41c48e3228ce8f22ca705fa8c
4
- data.tar.gz: 155fd2cbcd5b7a81afc1f2a2ab5e77358fed8b2d
3
+ metadata.gz: 5751d356e36de24bbaf807339790fa700b49cb2a
4
+ data.tar.gz: cff1e6160d5765ea6ff4c439fe0025558fe4d3d5
5
5
  SHA512:
6
- metadata.gz: 52aec11a763819d3c7d5a057fde58fd42ceb9b873c3116e3d4529abbc8edcbf8885748d34dc6f62ecfa414f10570fe650c7d50c59e8f918f0966f9b8cede3b51
7
- data.tar.gz: aa6c9538b99d3a4984f18f3b7ff8f2fcdd4e40e562e7dc93d581cbf98c20d16cc41f4bf6fe9b07e1f5ee0bc7e7ae6e5fa42c36902fbc96953fbb437da0ebd5e4
6
+ metadata.gz: 786a246df433f641fb8c1a9286bebfcda5d48427ec9617a8e1934a354f9c2592220b8e65963bbd04fd5d71ed9a64c082b79305d4e3a59553e1b9c7a49041b9dd
7
+ data.tar.gz: 00cec2e7f2df17bf8f7b275b8f78d0013981c3c33883af830a96b0554fe0751706ad70514c7bfef861b08a8a7c302b53749185b959181158434dda7ab3fc2514
@@ -1,5 +1,3 @@
1
- require 'core_ext/array/indifferent_access'
2
- require 'core_ext/hash/indifferent_access'
3
1
  require 'faraday'
4
2
  require 'json'
5
3
 
@@ -15,7 +13,7 @@ module CMIS
15
13
  raise Exceptions::Unauthorized
16
14
  else
17
15
  if env[:response_headers][:content_type] =~ JSON_CONTENT_TYPE
18
- env[:body] = JSON.parse(env[:body]).with_indifferent_access
16
+ env[:body] = JSON.parse(env[:body])
19
17
  check_for_cmis_exception!(env[:body])
20
18
  end
21
19
  end
@@ -27,8 +25,8 @@ module CMIS
27
25
  def check_for_cmis_exception!(body)
28
26
  return unless body.is_a?(Hash)
29
27
 
30
- if exception = body[:exception]
31
- raise exception_class(exception), "#{exception}: #{body[:message]}"
28
+ if exception = body['exception']
29
+ raise exception_class(exception), "#{exception}: #{body['message']}"
32
30
  end
33
31
  end
34
32
 
data/lib/cmis/helpers.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'core_ext/hash/indifferent_access'
2
1
  require 'core_ext/string/underscore'
3
2
 
4
3
  module CMIS
@@ -54,16 +53,14 @@ module CMIS
54
53
 
55
54
  def get_properties_map(raw)
56
55
  if raw['succinctProperties']
57
- result = raw['succinctProperties']
56
+ raw['succinctProperties']
58
57
  elsif raw['properties']
59
- result = raw['properties'].reduce({}) do |h, (k, v)|
58
+ raw['properties'].reduce({}) do |h, (k, v)|
60
59
  h.merge(k => sanitize(v))
61
60
  end
62
61
  else
63
- result = {}
62
+ {}
64
63
  end
65
-
66
- result.with_indifferent_access
67
64
  end
68
65
 
69
66
  def sanitize(prop)
@@ -1,11 +1,10 @@
1
- require 'core_ext/hash/indifferent_access'
1
+ require 'core_ext/hash/keys'
2
2
  require 'core_ext/string/underscore'
3
3
 
4
4
  module CMIS
5
5
  class PropertyDefinition
6
6
  def initialize(hash = {})
7
- @hash = hash.with_indifferent_access
8
-
7
+ @hash = hash.stringify_keys
9
8
  @hash.each_key do |key|
10
9
  self.class.class_eval "def #{key.underscore};@hash['#{key}'];end"
11
10
  self.class.class_eval "def #{key.underscore}=(value);@hash['#{key}']=value;end"
data/lib/cmis/type.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'core_ext/hash/indifferent_access'
1
+ require 'core_ext/hash/keys'
2
2
  require 'core_ext/string/underscore'
3
3
  require 'json'
4
4
 
@@ -8,7 +8,7 @@ module CMIS
8
8
 
9
9
  def initialize(hash, repository)
10
10
  @repository = repository
11
- @hash = hash.with_indifferent_access
11
+ @hash = hash.deep_stringify_keys
12
12
 
13
13
  properties = %w( id localName localNamespace queryName displayName baseId
14
14
  parentId description creatable fileable queryable
@@ -21,14 +21,15 @@ module CMIS
21
21
  self.class.class_eval "def #{key.underscore}=(value);@hash['#{key}']=value;end"
22
22
  end
23
23
 
24
- @hash['propertyDefinitions'] ||= HashWithIndifferentAccess.new
24
+ @hash['propertyDefinitions'] ||= {}
25
25
  @hash['propertyDefinitions'].each do |key, value|
26
26
  @hash['propertyDefinitions'][key] = PropertyDefinition.new(value)
27
27
  end
28
28
  end
29
29
 
30
30
  def add_property_definition(property)
31
- property_definitions[property[:id]] = property
31
+ property.stringify_keys!
32
+ property_definitions[property['id']] = property
32
33
  end
33
34
 
34
35
  def create
@@ -36,8 +37,9 @@ module CMIS
36
37
  end
37
38
 
38
39
  def update(changed_property_defs, opts = {})
40
+ changed_property_defs.deep_stringify_keys!
39
41
  new_defs = changed_property_defs.map(&:to_hash).reduce({}) do |result, element|
40
- result[element[:id]] = element
42
+ result[element['id']] = element
41
43
  result
42
44
  end
43
45
 
data/lib/cmis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CMIS
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
@@ -59,9 +59,9 @@ module CMIS
59
59
  describe '#acls' do
60
60
  it 'returns acls' do
61
61
  acls = @document.acls
62
- expect(acls).to have_key(:aces)
63
- expect(acls).to have_key(:isExact)
64
- expect([true, false]).to include(acls[:isExact])
62
+ expect(acls).to have_key('aces')
63
+ expect(acls).to have_key('isExact')
64
+ expect([true, false]).to include(acls['isExact'])
65
65
  end
66
66
  end
67
67
 
data/spec/spec_helper.rb CHANGED
@@ -10,14 +10,14 @@ module SpecHelpers
10
10
  @@server ||= CMIS::Server.new(options['server'])
11
11
  end
12
12
 
13
- def repository
14
- @@repository ||= server.repository(repository_id)
15
- end
16
-
17
13
  def repository_id
18
14
  @@repository_id ||= options['repository']
19
15
  end
20
16
 
17
+ def repository
18
+ @@repository ||= server.repository(repository_id)
19
+ end
20
+
21
21
  private
22
22
 
23
23
  def options
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmis-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenneth Geerts
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-27 00:00:00.000000000 Z
12
+ date: 2014-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -68,9 +68,7 @@ files:
68
68
  - lib/cmis/server.rb
69
69
  - lib/cmis/type.rb
70
70
  - lib/cmis/version.rb
71
- - lib/core_ext/array/indifferent_access.rb
72
71
  - lib/core_ext/hash/compact.rb
73
- - lib/core_ext/hash/indifferent_access.rb
74
72
  - lib/core_ext/hash/keys.rb
75
73
  - lib/core_ext/hash/slice.rb
76
74
  - lib/core_ext/string/underscore.rb
@@ -1,14 +0,0 @@
1
- class Array
2
- def with_indifferent_access
3
- map do |value|
4
- case value
5
- when Hash
6
- value.with_indifferent_access
7
- when Array
8
- value.with_indifferent_access
9
- else
10
- value
11
- end
12
- end
13
- end
14
- end
@@ -1,288 +0,0 @@
1
- require 'core_ext/hash/keys'
2
-
3
- # Implements a hash where keys <tt>:foo</tt> and <tt>"foo"</tt> are considered
4
- # to be the same.
5
- #
6
- # rgb = HashWithIndifferentAccess.new
7
- #
8
- # rgb[:black] = '#000000'
9
- # rgb[:black] # => '#000000'
10
- # rgb['black'] # => '#000000'
11
- #
12
- # rgb['white'] = '#FFFFFF'
13
- # rgb[:white] # => '#FFFFFF'
14
- # rgb['white'] # => '#FFFFFF'
15
- #
16
- # Internally symbols are mapped to strings when used as keys in the entire
17
- # writing interface (calling <tt>[]=</tt>, <tt>merge</tt>, etc). This
18
- # mapping belongs to the public interface. For example, given:
19
- #
20
- # hash = HashWithIndifferentAccess.new(a: 1)
21
- #
22
- # You are guaranteed that the key is returned as a string:
23
- #
24
- # hash.keys # => ["a"]
25
- #
26
- # Technically other types of keys are accepted:
27
- #
28
- # hash = HashWithIndifferentAccess.new(a: 1)
29
- # hash[0] = 0
30
- # hash # => {"a"=>1, 0=>0}
31
- #
32
- # but this class is intended for use cases where strings or symbols are the
33
- # expected keys and it is convenient to understand both as the same. For
34
- # example the +params+ hash in Ruby on Rails.
35
- #
36
- # Note that core extensions define <tt>Hash#with_indifferent_access</tt>:
37
- #
38
- # rgb = { black: '#000000', white: '#FFFFFF' }.with_indifferent_access
39
- #
40
- # which may be handy.
41
- class HashWithIndifferentAccess < Hash
42
- # Returns +true+ so that <tt>Array#extract_options!</tt> finds members of
43
- # this class.
44
- def extractable_options?
45
- true
46
- end
47
-
48
- def with_indifferent_access
49
- dup
50
- end
51
-
52
- def nested_under_indifferent_access
53
- self
54
- end
55
-
56
- def initialize(constructor = {})
57
- if constructor.is_a?(Hash)
58
- super()
59
- update(constructor)
60
- else
61
- super(constructor)
62
- end
63
- end
64
-
65
- def default(key = nil)
66
- if key.is_a?(Symbol) && include?(key = key.to_s)
67
- self[key]
68
- else
69
- super
70
- end
71
- end
72
-
73
- def self.new_from_hash_copying_default(hash)
74
- new(hash).tap do |new_hash|
75
- new_hash.default = hash.default
76
- end
77
- end
78
-
79
- def self.[](*args)
80
- new.merge!(Hash[*args])
81
- end
82
-
83
- alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
84
- alias_method :regular_update, :update unless method_defined?(:regular_update)
85
-
86
- # Assigns a new value to the hash:
87
- #
88
- # hash = HashWithIndifferentAccess.new
89
- # hash[:key] = 'value'
90
- #
91
- # This value can be later fetched using either +:key+ or +'key'+.
92
- def []=(key, value)
93
- regular_writer(convert_key(key), convert_value(value, for: :assignment))
94
- end
95
-
96
- alias_method :store, :[]=
97
-
98
- # Updates the receiver in-place, merging in the hash passed as argument:
99
- #
100
- # hash_1 = HashWithIndifferentAccess.new
101
- # hash_1[:key] = 'value'
102
- #
103
- # hash_2 = HashWithIndifferentAccess.new
104
- # hash_2[:key] = 'New Value!'
105
- #
106
- # hash_1.update(hash_2) # => {"key"=>"New Value!"}
107
- #
108
- # The argument can be either an
109
- # <tt>HashWithIndifferentAccess</tt> or a regular +Hash+.
110
- # In either case the merge respects the semantics of indifferent access.
111
- #
112
- # If the argument is a regular hash with keys +:key+ and +"key"+ only one
113
- # of the values end up in the receiver, but which one is unspecified.
114
- #
115
- # When given a block, the value for duplicated keys will be determined
116
- # by the result of invoking the block with the duplicated key, the value
117
- # in the receiver, and the value in +other_hash+. The rules for duplicated
118
- # keys follow the semantics of indifferent access:
119
- #
120
- # hash_1[:key] = 10
121
- # hash_2['key'] = 12
122
- # hash_1.update(hash_2) { |key, old, new| old + new } # => {"key"=>22}
123
- def update(other_hash)
124
- if other_hash.is_a? HashWithIndifferentAccess
125
- super(other_hash)
126
- else
127
- other_hash.each_pair do |key, value|
128
- if block_given? && key?(key)
129
- value = yield(convert_key(key), self[key], value)
130
- end
131
- regular_writer(convert_key(key), convert_value(value))
132
- end
133
- self
134
- end
135
- end
136
-
137
- alias_method :merge!, :update
138
-
139
- # Checks the hash for a key matching the argument passed in:
140
- #
141
- # hash = HashWithIndifferentAccess.new
142
- # hash['key'] = 'value'
143
- # hash.key?(:key) # => true
144
- # hash.key?('key') # => true
145
- def key?(key)
146
- super(convert_key(key))
147
- end
148
-
149
- alias_method :include?, :key?
150
- alias_method :has_key?, :key?
151
- alias_method :member?, :key?
152
-
153
- # Same as <tt>Hash#fetch</tt> where the key passed as argument can be
154
- # either a string or a symbol:
155
- #
156
- # counters = HashWithIndifferentAccess.new
157
- # counters[:foo] = 1
158
- #
159
- # counters.fetch('foo') # => 1
160
- # counters.fetch(:bar, 0) # => 0
161
- # counters.fetch(:bar) { |key| 0 } # => 0
162
- # counters.fetch(:zoo) # => KeyError: key not found: "zoo"
163
- def fetch(key, *extras)
164
- super(convert_key(key), *extras)
165
- end
166
-
167
- # Returns an array of the values at the specified indices:
168
- #
169
- # hash = HashWithIndifferentAccess.new
170
- # hash[:a] = 'x'
171
- # hash[:b] = 'y'
172
- # hash.values_at('a', 'b') # => ["x", "y"]
173
- def values_at(*indices)
174
- indices.collect { |key| self[convert_key(key)] }
175
- end
176
-
177
- # Returns an exact copy of the hash.
178
- def dup
179
- self.class.new(self).tap do |new_hash|
180
- new_hash.default = default
181
- end
182
- end
183
-
184
- # This method has the same semantics of +update+, except it does not
185
- # modify the receiver but rather returns a new hash with indifferent
186
- # access with the result of the merge.
187
- def merge(hash, &block)
188
- self.dup.update(hash, &block)
189
- end
190
-
191
- # Like +merge+ but the other way around: Merges the receiver into the
192
- # argument and returns a new hash with indifferent access as result:
193
- #
194
- # hash = HashWithIndifferentAccess.new
195
- # hash['a'] = nil
196
- # hash.reverse_merge(a: 0, b: 1) # => {"a"=>nil, "b"=>1}
197
- def reverse_merge(other_hash)
198
- super(self.class.new_from_hash_copying_default(other_hash))
199
- end
200
-
201
- # Same semantics as +reverse_merge+ but modifies the receiver in-place.
202
- def reverse_merge!(other_hash)
203
- replace(reverse_merge( other_hash ))
204
- end
205
-
206
- # Replaces the contents of this hash with other_hash.
207
- #
208
- # h = { "a" => 100, "b" => 200 }
209
- # h.replace({ "c" => 300, "d" => 400 }) # => {"c"=>300, "d"=>400}
210
- def replace(other_hash)
211
- super(self.class.new_from_hash_copying_default(other_hash))
212
- end
213
-
214
- # Removes the specified key from the hash.
215
- def delete(key)
216
- super(convert_key(key))
217
- end
218
-
219
- def stringify_keys!; self end
220
- def deep_stringify_keys!; self end
221
- def stringify_keys; dup end
222
- def deep_stringify_keys; dup end
223
- undef :symbolize_keys!
224
- undef :deep_symbolize_keys!
225
- def symbolize_keys; to_hash.symbolize_keys! end
226
- def deep_symbolize_keys; to_hash.deep_symbolize_keys! end
227
- def to_options!; self end
228
-
229
- def select(*args, &block)
230
- dup.tap { |hash| hash.select!(*args, &block) }
231
- end
232
-
233
- def reject(*args, &block)
234
- dup.tap { |hash| hash.reject!(*args, &block) }
235
- end
236
-
237
- # Convert to a regular hash with string keys.
238
- def to_hash
239
- _new_hash= {}
240
- each do |key, value|
241
- _new_hash[convert_key(key)] = convert_value(value, for: :to_hash)
242
- end
243
- Hash.new(default).merge!(_new_hash)
244
- end
245
-
246
- protected
247
- def convert_key(key)
248
- key.kind_of?(Symbol) ? key.to_s : key
249
- end
250
-
251
- def convert_value(value, options = {})
252
- if value.is_a? Hash
253
- if options[:for] == :to_hash
254
- value.to_hash
255
- else
256
- value.nested_under_indifferent_access
257
- end
258
- elsif value.is_a?(Array)
259
- unless options[:for] == :assignment
260
- value = value.dup
261
- end
262
- value.map! { |e| convert_value(e, options) }
263
- else
264
- value
265
- end
266
- end
267
- end
268
-
269
- class Hash
270
- # Returns a <tt>HashWithIndifferentAccess</tt> out of its receiver:
271
- #
272
- # { a: 1 }.with_indifferent_access['a'] # => 1
273
- def with_indifferent_access
274
- HashWithIndifferentAccess.new_from_hash_copying_default(self)
275
- end
276
-
277
- # Called when object is nested under an object that receives
278
- # #with_indifferent_access. This method will be called on the current object
279
- # by the enclosing object and is aliased to #with_indifferent_access by
280
- # default. Subclasses of Hash may overwrite this method to return +self+ if
281
- # converting to an <tt>HashWithIndifferentAccess</tt> would not be
282
- # desirable.
283
- #
284
- # b = { b: 1 }
285
- # { a: b }.with_indifferent_access['a'] # calls b.nested_under_indifferent_access
286
- # # => {"b"=>32}
287
- alias nested_under_indifferent_access with_indifferent_access
288
- end