opera-mobile-store-sdk 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,43 +1,41 @@
1
- module Opera
2
- module MobileStore
3
- class ProductImage
4
-
5
- include ActiveModel::Model
6
- include ActiveModel::Serialization
7
-
8
- # All attributes are Read-Only...
9
- attr_accessor :type, :width, :height, :url
10
-
11
- def attributes
12
- [:type, :width, :height, :url].inject({}) do |hash, field_name|
13
- field_value = self.public_send field_name
14
- hash[field_name.to_s] = field_value if field_value.present?
15
- hash
16
- end
17
- end
1
+ require "active_model"
18
2
 
19
- def self.build_from_nokogiri_node(node)
3
+ module Opera::MobileStore
4
+ class ProductImage
20
5
 
21
- data = {
22
- type: node.name,
23
- url: node.text.strip
24
- }
6
+ include ActiveModel::Model
7
+ include ActiveModel::Serialization
25
8
 
26
- # Extract width + height data:
27
- width = node.xpath("string(@width)")
28
- height = node.xpath("string(@height)")
29
- data[:width] = width.to_i if width.present?
30
- data[:height] = width.to_i if height.present?
9
+ include Opera::MobileStore::InspectableAttributes
31
10
 
32
- self.new data
33
- end
11
+ # All attributes are Read-Only...
12
+ attr_accessor :type, :width, :height, :url
34
13
 
35
- def inspect
36
- "<#{self.class.name} #{attributes.inspect}>"
14
+ def attributes
15
+ [:type, :width, :height, :url].inject({}) do |hash, field_name|
16
+ field_value = self.public_send field_name
17
+ hash[field_name.to_s] = field_value if field_value.present?
18
+ hash
37
19
  end
20
+ end
21
+
22
+ def self.build_from_nokogiri_node(node)
38
23
 
39
- self.singleton_class.send :alias_method, :deserialize, :new
24
+ data = {
25
+ type: node.name,
26
+ url: node.text.strip
27
+ }
40
28
 
29
+ # Extract width + height data:
30
+ width = node.xpath("string(@width)")
31
+ height = node.xpath("string(@height)")
32
+ data[:width] = width.to_i if width.present?
33
+ data[:height] = width.to_i if height.present?
34
+
35
+ self.new data
41
36
  end
37
+
38
+ self.singleton_class.send :alias_method, :deserialize, :new
39
+
42
40
  end
43
41
  end
@@ -1,32 +1,30 @@
1
- module Opera
2
- module MobileStore
3
- class ProductLocalization
1
+ require "active_model"
4
2
 
5
- include ActiveModel::Model
6
- include ActiveModel::Serialization
3
+ module Opera::MobileStore
4
+ class ProductLocalization
7
5
 
8
- # All attributes are Read-Only...
9
- attr_accessor :language_code,
10
- :title,
11
- :short_description,
12
- :long_description
6
+ include ActiveModel::Model
7
+ include ActiveModel::Serialization
13
8
 
14
- def attributes
15
- [
16
- :language_code, :title, :short_description, :long_description
17
- ].inject({}) do |hash, field_name|
18
- field_value = self.public_send field_name
19
- hash[field_name.to_s] = field_value if field_value.present?
20
- hash
21
- end
22
- end
9
+ include Opera::MobileStore::InspectableAttributes
10
+
11
+ # All attributes are Read-Only...
12
+ attr_accessor :language_code,
13
+ :title,
14
+ :short_description,
15
+ :long_description
23
16
 
24
- def inspect
25
- "<#{self.class.name} #{attributes.inspect}>"
17
+ def attributes
18
+ [
19
+ :language_code, :title, :short_description, :long_description
20
+ ].inject({}) do |hash, field_name|
21
+ field_value = self.public_send field_name
22
+ hash[field_name.to_s] = field_value if field_value.present?
23
+ hash
26
24
  end
25
+ end
27
26
 
28
- self.singleton_class.send :alias_method, :deserialize, :new
27
+ self.singleton_class.send :alias_method, :deserialize, :new
29
28
 
30
- end
31
29
  end
32
30
  end
@@ -8,8 +8,16 @@ module Opera
8
8
  def initialize(params={})
9
9
  super
10
10
 
11
- # Register in the identity map:
12
- self.class.identity_map[self.id] = self
11
+ # Upsert in the identity map:
12
+ if self.class.identity_map.key? self.id
13
+ params.each do |field_name, field_value|
14
+ self.class.identity_map[self.id].public_send(
15
+ "#{field_name}=", field_value
16
+ )
17
+ end
18
+ else
19
+ self.class.identity_map[self.id] = self
20
+ end
13
21
  end
14
22
 
15
23
  module ClassMethods
@@ -26,7 +34,7 @@ module Opera
26
34
  end
27
35
  end
28
36
 
29
- def registered?(object_id)
37
+ def identity_mapped?(object_id)
30
38
  identity_map.key? object_id
31
39
  end
32
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opera-mobile-store-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-04-22 00:00:00.000000000 Z
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -127,11 +127,11 @@ files:
127
127
  - bin/setup
128
128
  - lib/opera-mobile-store-sdk.rb
129
129
  - lib/opera-mobile-store-sdk/version.rb
130
- - lib/opera/mobile_store/author.rb
131
130
  - lib/opera/mobile_store/build.rb
132
131
  - lib/opera/mobile_store/build_file.rb
133
132
  - lib/opera/mobile_store/category.rb
134
133
  - lib/opera/mobile_store/developer.rb
134
+ - lib/opera/mobile_store/inspectable_attributes.rb
135
135
  - lib/opera/mobile_store/payment_info.rb
136
136
  - lib/opera/mobile_store/product.rb
137
137
  - lib/opera/mobile_store/product_image.rb
@@ -1,29 +0,0 @@
1
- module Opera
2
- module MobileStore
3
- class Author
4
-
5
- include ActiveModel::Model
6
- include ActiveModel::Serialization
7
-
8
- include Opera::MobileStoreSDK::IdentityMapable
9
-
10
- # All attributes are Read-Only...
11
- attr_accessor :id, :name, :email
12
-
13
- def attributes
14
- [:id, :name, :email].inject({}) do |hash, field_name|
15
- value = self.public_send field_name
16
- hash[field_name.to_s] = value unless value.nil?
17
- hash
18
- end
19
- end
20
-
21
- def inspect
22
- "<#{self.class.name} #{attributes.inspect}>"
23
- end
24
-
25
- self.singleton_class.send :alias_method, :deserialize, :new
26
-
27
- end
28
- end
29
- end