naranya_ecm-sdk 0.0.52 → 0.0.53

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: bfe5894d0cf5db142b03d0a20548038fa721dc86
4
- data.tar.gz: 6421ce63c3f6acecf3c23a7194ed1eaec1fe466f
3
+ metadata.gz: 1ca18ddb2dee136305ec964bd7a4e21e85aca031
4
+ data.tar.gz: cae662085784a09b9c704738d75440c7a70ab164
5
5
  SHA512:
6
- metadata.gz: 10cc3f36754e215986dc6757d8d3e48456c1cdca0e9b06867c33f5952d29ad84da99bd9ce46e79dc06dc221b6251a542cc1d2e48a91d504826d0e7a41ee25b7e
7
- data.tar.gz: 3331f2ddedc3f5844b2667c69abb18e4d7f3c556d1050c759548f7689fbfcb6b54ba3c389dd359df1625352124c23d17b0a512ed1a79f0c940625f3461d08e12
6
+ metadata.gz: 46ac57df6f1d22a4fa44f925235422aa2b4cd3c45522f395e4fb8618fee235df56846ec57323b32b6e85ff8fc75821fb36f363fd1f452073142fcdeab93642a1
7
+ data.tar.gz: 52458768d9951bad05c4d1aebf5ddeed03a1ec847c4521bc7f34f3a93381a4ff3d6079bd5e2da7bf3338afa449b98325c8f86de7f4b94dbe0af86fe8fd46c0b7
@@ -1,3 +1,3 @@
1
1
  module NaranyaEcm
2
- VERSION = "0.0.52"
2
+ VERSION = "0.0.53"
3
3
  end
@@ -12,7 +12,7 @@ module NaranyaEcm
12
12
  #
13
13
  # In order to create a Content Unit, the Content Object should contain at least the following attributes:
14
14
  # * <tt>lifecycle_name:</tt> Indicates whether the Content object follows a <tt>simple</tt> lifecycle, a <tt>validatable</tt> lifecycle (can't publish without some sort of editorial validation first), or any other significant lifecycle.
15
- # * <tt>title_translations:</tt> At least one localized title is required. This attribute is a Hash-like object, requiring the locale name as a key, and the localized string as value.
15
+ # * <tt>title_translations:</tt> At least one localized title is required. This attribute is a Hash-like object, requiring the locale name as a key, and the localized string as value.
16
16
  # * <tt>author:</tt> This string represents the name of the author of the content.
17
17
  #
18
18
  # === Other significant attributes
@@ -97,7 +97,7 @@ module NaranyaEcm
97
97
  # :attr: description_translations
98
98
  #
99
99
  # Hash-like containing all the description translations.
100
-
100
+
101
101
  ##
102
102
  # :attr: content_rating
103
103
  #
@@ -139,7 +139,7 @@ module NaranyaEcm
139
139
  #
140
140
  # A list of ContentVersion objects corresponding to changes in a versionable content.
141
141
  has_many :versions, class_name: :ContentVersion
142
-
142
+
143
143
  ##
144
144
  # :attr: current_version
145
145
  # :category: Associations
@@ -160,7 +160,7 @@ module NaranyaEcm
160
160
  #
161
161
  # A list of MediaResource objects associated directly to the Content.
162
162
  has_many :media_resources, class_name: :MediaResource, inverse_of: :content
163
-
163
+
164
164
  ###############################################################
165
165
  # StateMachine:
166
166
  include AASM
@@ -186,7 +186,7 @@ module NaranyaEcm
186
186
  # accept => true or false
187
187
  #
188
188
  # Triggers the <tt>accept</tt> event.
189
-
189
+
190
190
  ##
191
191
  # :method: accept!
192
192
  # :call-seq:
@@ -200,7 +200,7 @@ module NaranyaEcm
200
200
  # reject => true or false
201
201
  #
202
202
  # Triggers the <tt>reject</tt> event, which starts the Content transition to an <tt>:rejected</tt> state.
203
-
203
+
204
204
  ##
205
205
  # :method: reject!
206
206
  # :call-seq:
@@ -214,7 +214,7 @@ module NaranyaEcm
214
214
  # publish => true or false
215
215
  #
216
216
  # Triggers the <tt>publish</tt> event, which starts the Content transition to a <tt>:published</tt> state.
217
-
217
+
218
218
  ##
219
219
  # :method: publish!
220
220
  # :call-seq:
@@ -228,7 +228,7 @@ module NaranyaEcm
228
228
  # deactivate => true or false
229
229
  #
230
230
  # Triggers the <tt>deactivate</tt> event, which starts the Content transition to a <tt>:deactivated</tt> state.
231
-
231
+
232
232
  ##
233
233
  # :method: deactivate!
234
234
  # :call-seq:
@@ -285,7 +285,7 @@ module NaranyaEcm
285
285
  def simple_lifecycle?
286
286
  self.lifecycle_name == 'simple'
287
287
  end
288
-
288
+
289
289
  ##
290
290
  # :method: validatable_lifecycle?
291
291
  # :call-seq:
@@ -300,8 +300,10 @@ module NaranyaEcm
300
300
 
301
301
  # Validates that at least one title translation exists.
302
302
  def at_least_one_title_translation_must_exist
303
- errors.add :title_translations, "must have at least one translation" unless title_translations.keys.any?
303
+ unless title_translations.present? && title_translations.keys.any?
304
+ errors.add :title_translations, "must have at least one translation"
305
+ end
304
306
  end
305
-
307
+
306
308
  end
307
309
  end
@@ -10,7 +10,7 @@ module NaranyaEcm::Rest
10
10
  given_class_name = "#{@klass.name.deconstantize}::#{given_class_name}" if given_class_name.is_a?(Symbol)
11
11
  given_class_name.constantize
12
12
  end
13
-
13
+
14
14
  def initialize(klass, name, options = {})
15
15
  @klass, @name = klass, name
16
16
 
@@ -23,7 +23,7 @@ module NaranyaEcm::Rest
23
23
  @options = options.with_indifferent_access
24
24
 
25
25
  klass.send :attr_accessor, name
26
-
26
+
27
27
  end
28
28
  end
29
29
 
@@ -60,7 +60,7 @@ module NaranyaEcm::Rest
60
60
  relation = AssociationRelation.new(reflection.associated_class, reflection.foreign_key, self.id)
61
61
 
62
62
  relation.load new_value unless new_value.nil?
63
-
63
+
64
64
  instance_variable_set "@#{name}".to_sym, relation
65
65
  end
66
66
  end
@@ -98,8 +98,8 @@ module NaranyaEcm::Rest
98
98
  klass.send :define_method, "#{name}=".to_sym do |new_value|
99
99
  reflection = self.class.reflect_on_association(name)
100
100
  foreign_key_name = reflection.foreign_key
101
-
102
- new_value = reflection.associated_class.load new_value if new_value.is_a? Hash
101
+
102
+ new_value = reflection.associated_class.new new_value if new_value.is_a? Hash
103
103
  raise "Type Mismatch on #{self.class.name} ##{name}= #{new_value.inspect}" unless new_value.nil? || new_value.class == reflection.associated_class
104
104
 
105
105
  self.send "#{foreign_key_name}=".to_sym, new_value.nil? ? nil : new_value.id
@@ -152,4 +152,4 @@ module NaranyaEcm::Rest
152
152
  end
153
153
  end
154
154
 
155
- end
155
+ end
@@ -18,7 +18,7 @@ module NaranyaEcm::Rest
18
18
  protected
19
19
 
20
20
  def find_one(id)
21
- found_resource = self.load fetch_one(id)
21
+ found_resource = self._load_from_fetched_attributes fetch_one(id)
22
22
  found_resource.instance_variable_set("@new_resource", false)
23
23
  found_resource
24
24
  end
@@ -157,12 +157,6 @@ module NaranyaEcm::Rest
157
157
  .inject({}.with_indifferent_access) { |hash, accessor_name| hash[accessor_name] = self.send accessor_name; hash }
158
158
  end
159
159
 
160
- def load(params={})
161
- params.each do |attr, value|
162
- self.public_send("#{attr}=", value)
163
- end if params
164
- end
165
-
166
160
  def path
167
161
  "#{self.class.path}/#{self.id}"
168
162
  end
@@ -187,13 +181,6 @@ module NaranyaEcm::Rest
187
181
  @_fields ||= {}.with_indifferent_access
188
182
  end
189
183
 
190
- def load(*args)
191
- loaded = self.new
192
- loaded.load(*args)
193
- loaded.changed_attributes.clear
194
- loaded
195
- end
196
-
197
184
  def primary_key(name, options = {})
198
185
  attr_accessor name
199
186
  define_attribute_method name
@@ -253,6 +240,14 @@ module NaranyaEcm::Rest
253
240
  where()
254
241
  end
255
242
 
243
+ protected
244
+
245
+ def _load_from_fetched_attributes(*args)
246
+ loaded = self.new
247
+ loaded.send :_load_from_fetched_attributes!, *args
248
+ loaded
249
+ end
250
+
256
251
  end
257
252
 
258
253
  # Returns +true+ if the resource is read only.
@@ -273,6 +268,42 @@ module NaranyaEcm::Rest
273
268
 
274
269
  private
275
270
 
271
+ def _load_from_fetched_attributes!(params={})
272
+ if params
273
+
274
+ association_dictionary = self.class.send(:associations).inject({}) do |hash, keyval|
275
+ key, val = keyval
276
+ hash[key] = val.associated_class
277
+ hash
278
+ end
279
+
280
+ nested_attributes = params.slice *association_dictionary.keys
281
+ self_attributes = params.reject { |k,v| nested_attributes.keys.include? k }
282
+
283
+ loaded_associations = nested_attributes.inject({}) do |hash, keyval|
284
+ association_name, association_attributes = keyval
285
+ association_class = association_dictionary[association_name]
286
+
287
+ hash[association_name] = if association_attributes.is_a?(Array)
288
+ association_attributes.map do |x|
289
+ association_class.send :_load_from_fetched_attributes, x
290
+ end
291
+ else
292
+ association_class.send :_load_from_fetched_attributes, association_attributes
293
+ end
294
+ hash
295
+ end
296
+
297
+ # Set the given params and the inflated association params:
298
+ self_attributes.merge(loaded_associations).each do |attr, value|
299
+ self.public_send("#{attr}=", value)
300
+ end
301
+
302
+ changed_attributes.clear
303
+ end
304
+ @new_resource = false
305
+ end
306
+
276
307
  def init_internals
277
308
  @readonly = false
278
309
  @destroyed = false
@@ -253,9 +253,7 @@ module NaranyaEcm::Rest
253
253
 
254
254
  def reload
255
255
  response = NContent::SDK::RESTClient.get "#{path}.json"
256
-
257
- load(response.body)
258
- @new_resource = false
256
+ send :_load_from_fetched_attributes!, response.body
259
257
  true
260
258
  end
261
259
 
@@ -292,8 +290,7 @@ module NaranyaEcm::Rest
292
290
  )
293
291
  end
294
292
 
295
- self.load(response.body)
296
- @new_resource = false
293
+ send :_load_from_fetched_attributes!, response.body
297
294
  true
298
295
  rescue UnprocessableEntity => e
299
296
  self.load_server_errors(e.response.body)
@@ -42,8 +42,7 @@ module NaranyaEcm::Rest
42
42
 
43
43
  @elements = given_list.map do |element|
44
44
  if element.is_a?(Hash)
45
- loaded_element = @klass.load(element)
46
- loaded_element.instance_variable_set("@new_resource", false)
45
+ loaded_element = @klass.send :_load_from_fetched_attributes, element
47
46
  loaded_element
48
47
  else
49
48
  element
@@ -58,7 +57,7 @@ module NaranyaEcm::Rest
58
57
 
59
58
  def materialize!
60
59
  @elements = fetch_from_server.map do |s|
61
- resource = klass.load s
60
+ resource = klass.send :_load_from_fetched_attributes, s
62
61
  resource.instance_variable_set("@new_resource", false)
63
62
  resource
64
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naranya_ecm-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.52
4
+ version: 0.0.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Quintanilla
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-18 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport