naranya_ecm-sdk 0.0.30 → 0.0.31

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: ef52f660e12d9616de3d74f068dfa1cae6bb580f
4
- data.tar.gz: 4e0f764bca050029c135a74ccbefce484dbfd794
3
+ metadata.gz: fa9acc400aae110158ac9b6cf303ba9f83a68665
4
+ data.tar.gz: 4279705e4e548df06969b369453089bd8173cf3d
5
5
  SHA512:
6
- metadata.gz: 48ed78c824ae239e589085eb99778e03a8443a34ded280d56f4fe6f55324c85cf52e9017b5ff1dd5d5bfaaf2ea48fee61463f60bff3e98d36f6dc36d80b08a58
7
- data.tar.gz: a8d9213a06ade35a93d84c54e7fddcbe81d5c7d99cac7acd4ade4d695bc55301da210d300e657a7db358e00ea9f106712918c283ae7e340cee47f1f18eb2bf77
6
+ metadata.gz: 8f2ccd99f062a6bee18b33af21f0942fed31d18f5f8a24e8e3ed1422b416d6991f2da682a96278bc69479a2f169f68dbf192b8b3f26dd68c8bbb3e4131482aca
7
+ data.tar.gz: 52b2859cae8701e6e7bccd776e82e5b018ec72d2cf145f49be8f609c14ec6b27725f7bb78429479b33de8f9cf399ba9eff8da70b0af869bdd6bc280ab7729313
@@ -0,0 +1,23 @@
1
+
2
+ require 'naranya_ecm/rest/relation'
3
+
4
+ module NaranyaEcm::Rest
5
+ class AssociationRelation < Relation
6
+ attr_reader :foreign_key_name, :foreign_key_value
7
+
8
+ def initialize(given_klass, given_foreign_key_name, given_foreign_key_value)
9
+
10
+ raise ArgumentError unless given_foreign_key_name.present?
11
+
12
+ @foreign_key_name, @foreign_key_value = given_foreign_key_name, given_foreign_key_value
13
+
14
+ super(given_klass, foreign_key_name => foreign_key_value)
15
+
16
+ end
17
+
18
+ def fetch_from_server
19
+ foreign_key_value.present? ? super : []
20
+ end
21
+
22
+ end
23
+ end
@@ -47,7 +47,8 @@ module NaranyaEcm::Rest
47
47
  foreign_key = (self.class.name.demodulize.underscore + '_id').to_sym
48
48
  value = self.instance_variable_set(
49
49
  "@#{name}".to_sym,
50
- reflection.associated_class.where(foreign_key => self.id)
50
+ # reflection.associated_class.where(foreign_key => self.id)
51
+ AssociationRelation.new(reflection.associated_class, reflection.foreign_key, self.id)
51
52
  )
52
53
  end
53
54
  value
@@ -56,7 +57,7 @@ module NaranyaEcm::Rest
56
57
  # Define the setter
57
58
  klass.send :define_method, "#{name}=".to_sym do |new_value|
58
59
  reflection = self.class.reflect_on_association(name)
59
- relation = Relation.new(reflection.associated_class, { reflection.foreign_key => self.id })
60
+ relation = AssociationRelation.new(reflection.associated_class, reflection.foreign_key, self.id)
60
61
 
61
62
  relation.load new_value unless new_value.nil?
62
63
 
@@ -1,3 +1,3 @@
1
1
  module NaranyaEcm
2
- VERSION = "0.0.30"
2
+ VERSION = "0.0.31"
3
3
  end
@@ -30,6 +30,7 @@ module NaranyaEcm
30
30
  autoload :Model
31
31
  autoload :FinderMethods
32
32
  autoload :Relation
33
+ autoload :AssociationRelation
33
34
  end
34
35
 
35
36
  autoload_under 'models' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naranya_ecm-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Quintanilla
@@ -177,6 +177,7 @@ files:
177
177
  - lib/naranya_ecm/models/content_version.rb
178
178
  - lib/naranya_ecm/models/download_authorization.rb
179
179
  - lib/naranya_ecm/models/media_resource.rb
180
+ - lib/naranya_ecm/rest/association_relation.rb
180
181
  - lib/naranya_ecm/rest/associations.rb
181
182
  - lib/naranya_ecm/rest/client.rb
182
183
  - lib/naranya_ecm/rest/errors.rb