syncano 4.0.0.alpha1 → 4.0.0.alpha2
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 +4 -4
- data/README.md +8 -157
- data/circle.yml +1 -1
- data/lib/syncano.rb +38 -11
- data/lib/syncano/api.rb +20 -2
- data/lib/syncano/api/endpoints.rb +17 -0
- data/lib/syncano/connection.rb +46 -54
- data/lib/syncano/poller.rb +55 -0
- data/lib/syncano/resources.rb +48 -16
- data/lib/syncano/resources/base.rb +46 -56
- data/lib/syncano/resources/paths.rb +48 -0
- data/lib/syncano/resources/resource_invalid.rb +15 -0
- data/lib/syncano/response.rb +55 -0
- data/lib/syncano/schema.rb +10 -29
- data/lib/syncano/schema/attribute_definition.rb +2 -2
- data/lib/syncano/schema/endpoints_whitelist.rb +40 -0
- data/lib/syncano/schema/resource_definition.rb +5 -0
- data/lib/syncano/upload_io.rb +7 -0
- data/lib/syncano/version.rb +1 -1
- data/spec/integration/syncano_spec.rb +220 -15
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/connection_spec.rb +34 -97
- data/spec/unit/resources/paths_spec.rb +21 -0
- data/spec/unit/resources_base_spec.rb +77 -16
- data/spec/unit/response_spec.rb +75 -0
- data/spec/unit/schema/resource_definition_spec.rb +10 -0
- data/spec/unit/schema_spec.rb +5 -55
- data/syncano.gemspec +4 -0
- metadata +69 -13
- data/lib/active_attr/dirty.rb +0 -26
- data/lib/active_attr/typecasting/hash_typecaster.rb +0 -34
- data/lib/active_attr/typecasting_override.rb +0 -29
- data/lib/syncano/model/associations.rb +0 -121
- data/lib/syncano/model/associations/base.rb +0 -38
- data/lib/syncano/model/associations/belongs_to.rb +0 -30
- data/lib/syncano/model/associations/has_many.rb +0 -75
- data/lib/syncano/model/associations/has_one.rb +0 -22
- data/lib/syncano/model/base.rb +0 -257
- data/lib/syncano/model/callbacks.rb +0 -49
- data/lib/syncano/model/scope_builder.rb +0 -158
data/syncano.gemspec
CHANGED
@@ -25,4 +25,8 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_dependency 'activesupport', '>= 4.0'
|
26
26
|
spec.add_dependency 'active_attr', '~> 0.8'
|
27
27
|
spec.add_dependency 'dirty_hashy', '~> 0.2'
|
28
|
+
spec.add_dependency 'celluloid'
|
29
|
+
spec.add_dependency 'celluloid-io'
|
30
|
+
spec.add_dependency 'mimetype-fu'
|
31
|
+
spec.add_dependency 'http', '= 0.7.4' # should work with no version constraint once 0.8.2 is released https://github.com/httprb/http.rb/issues/203#issuecomment-100299898
|
28
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syncano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Zadrożny
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -95,6 +95,62 @@ dependencies:
|
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0.2'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: celluloid
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: celluloid-io
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: mimetype-fu
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: http
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 0.7.4
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 0.7.4
|
98
154
|
description: A Ruby client that provides convenient interface for the Syncano api.
|
99
155
|
email:
|
100
156
|
- piotr.zadrozny@mindpower.pl
|
@@ -112,29 +168,25 @@ files:
|
|
112
168
|
- README.md
|
113
169
|
- Rakefile
|
114
170
|
- circle.yml
|
115
|
-
- lib/active_attr/dirty.rb
|
116
|
-
- lib/active_attr/typecasting/hash_typecaster.rb
|
117
|
-
- lib/active_attr/typecasting_override.rb
|
118
171
|
- lib/syncano.rb
|
119
172
|
- lib/syncano/api.rb
|
173
|
+
- lib/syncano/api/endpoints.rb
|
120
174
|
- lib/syncano/connection.rb
|
121
|
-
- lib/syncano/
|
122
|
-
- lib/syncano/model/associations/base.rb
|
123
|
-
- lib/syncano/model/associations/belongs_to.rb
|
124
|
-
- lib/syncano/model/associations/has_many.rb
|
125
|
-
- lib/syncano/model/associations/has_one.rb
|
126
|
-
- lib/syncano/model/base.rb
|
127
|
-
- lib/syncano/model/callbacks.rb
|
128
|
-
- lib/syncano/model/scope_builder.rb
|
175
|
+
- lib/syncano/poller.rb
|
129
176
|
- lib/syncano/query_builder.rb
|
130
177
|
- lib/syncano/resources.rb
|
131
178
|
- lib/syncano/resources/base.rb
|
132
179
|
- lib/syncano/resources/collection.rb
|
180
|
+
- lib/syncano/resources/paths.rb
|
181
|
+
- lib/syncano/resources/resource_invalid.rb
|
133
182
|
- lib/syncano/resources/space.rb
|
183
|
+
- lib/syncano/response.rb
|
134
184
|
- lib/syncano/schema.rb
|
135
185
|
- lib/syncano/schema/attribute_definition.rb
|
186
|
+
- lib/syncano/schema/endpoints_whitelist.rb
|
136
187
|
- lib/syncano/schema/resource_definition.rb
|
137
188
|
- lib/syncano/scope.rb
|
189
|
+
- lib/syncano/upload_io.rb
|
138
190
|
- lib/syncano/version.rb
|
139
191
|
- spec/integration/syncano_spec.rb
|
140
192
|
- spec/spec_helper.rb
|
@@ -142,8 +194,10 @@ files:
|
|
142
194
|
- spec/unit/connection_spec.rb
|
143
195
|
- spec/unit/query_builder_spec.rb
|
144
196
|
- spec/unit/resources/collection_spec.rb
|
197
|
+
- spec/unit/resources/paths_spec.rb
|
145
198
|
- spec/unit/resources/space_spec.rb
|
146
199
|
- spec/unit/resources_base_spec.rb
|
200
|
+
- spec/unit/response_spec.rb
|
147
201
|
- spec/unit/schema/attribute_definition_spec.rb
|
148
202
|
- spec/unit/schema/resource_definition_spec.rb
|
149
203
|
- spec/unit/schema_spec.rb
|
@@ -180,8 +234,10 @@ test_files:
|
|
180
234
|
- spec/unit/connection_spec.rb
|
181
235
|
- spec/unit/query_builder_spec.rb
|
182
236
|
- spec/unit/resources/collection_spec.rb
|
237
|
+
- spec/unit/resources/paths_spec.rb
|
183
238
|
- spec/unit/resources/space_spec.rb
|
184
239
|
- spec/unit/resources_base_spec.rb
|
240
|
+
- spec/unit/response_spec.rb
|
185
241
|
- spec/unit/schema/attribute_definition_spec.rb
|
186
242
|
- spec/unit/schema/resource_definition_spec.rb
|
187
243
|
- spec/unit/schema_spec.rb
|
data/lib/active_attr/dirty.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
require 'active_model/dirty'
|
3
|
-
require 'active_attr'
|
4
|
-
|
5
|
-
# Overwritting ActiveAttr module
|
6
|
-
module ActiveAttr
|
7
|
-
# Overwritting ActiveAttr::Dirty module
|
8
|
-
module Dirty
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
include ActiveModel::Dirty
|
11
|
-
|
12
|
-
# Class methods for ActiveAttr::Dirty module
|
13
|
-
module ClassMethods
|
14
|
-
# Overwritten attribute! method
|
15
|
-
# @param [Symbol] name
|
16
|
-
# @param [Hash] options
|
17
|
-
def attribute!(name, options = {})
|
18
|
-
super(name, options)
|
19
|
-
define_method("#{name}=") do |value|
|
20
|
-
send("#{name}_will_change!") unless value == read_attribute(name)
|
21
|
-
super(value)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
2
|
-
|
3
|
-
module ActiveAttr
|
4
|
-
module Typecasting
|
5
|
-
# Typecasts an Object to a HashWithInddifferentAccess
|
6
|
-
#
|
7
|
-
# @example Usage
|
8
|
-
# typecaster = HashTypecaster.new
|
9
|
-
# typecaster.call([[:foo, :bar]]) #=> { foo: :bar }
|
10
|
-
#
|
11
|
-
# @since 0.5.0
|
12
|
-
class HashTypecaster
|
13
|
-
# Typecasts an object to a HashWithInddifferentAccess
|
14
|
-
#
|
15
|
-
# Attempts to convert using #to_h.
|
16
|
-
#
|
17
|
-
# @example Typecast an Array
|
18
|
-
# typecaster.call([[:foo, :bar]]) #=> { foo: :bar }
|
19
|
-
#
|
20
|
-
# @param [Object, #to_h] value The object to typecast
|
21
|
-
#
|
22
|
-
# @return [HashWithInddifferentAccess] The result of typecasting
|
23
|
-
#
|
24
|
-
# @since 0.5.0
|
25
|
-
def call(value)
|
26
|
-
if value.respond_to? :to_h
|
27
|
-
HashWithIndifferentAccess.new(value.to_h)
|
28
|
-
else
|
29
|
-
HashWithIndifferentAccess.new
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'active_attr/typecasting/big_decimal_typecaster'
|
2
|
-
require 'active_attr/typecasting/boolean'
|
3
|
-
require 'active_attr/typecasting/boolean_typecaster'
|
4
|
-
require 'active_attr/typecasting/date_time_typecaster'
|
5
|
-
require 'active_attr/typecasting/date_typecaster'
|
6
|
-
require 'active_attr/typecasting/float_typecaster'
|
7
|
-
require 'active_attr/typecasting/integer_typecaster'
|
8
|
-
require 'active_attr/typecasting/object_typecaster'
|
9
|
-
require 'active_attr/typecasting/string_typecaster'
|
10
|
-
require 'active_attr/typecasting/hash_typecaster'
|
11
|
-
require 'active_attr/typecasting/unknown_typecaster_error'
|
12
|
-
|
13
|
-
module ActiveAttr
|
14
|
-
module Typecasting
|
15
|
-
remove_const(:TYPECASTER_MAP) if defined?(TYPECASTER_MAP)
|
16
|
-
|
17
|
-
TYPECASTER_MAP = {
|
18
|
-
BigDecimal => BigDecimalTypecaster,
|
19
|
-
Boolean => BooleanTypecaster,
|
20
|
-
Date => DateTypecaster,
|
21
|
-
DateTime => DateTimeTypecaster,
|
22
|
-
Float => FloatTypecaster,
|
23
|
-
Integer => IntegerTypecaster,
|
24
|
-
Object => ObjectTypecaster,
|
25
|
-
String => StringTypecaster,
|
26
|
-
Hash => HashTypecaster
|
27
|
-
}.freeze
|
28
|
-
end
|
29
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'syncano/model/associations/belongs_to'
|
2
|
-
require 'syncano/model/associations/has_many'
|
3
|
-
require 'syncano/model/associations/has_one'
|
4
|
-
|
5
|
-
module Syncano
|
6
|
-
module Model
|
7
|
-
# Module with associations functionality for Syncano::Model
|
8
|
-
module Associations
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
included do
|
12
|
-
private
|
13
|
-
|
14
|
-
class_attribute :_associations
|
15
|
-
end
|
16
|
-
|
17
|
-
# Class methods for Syncano::Model::Associations module
|
18
|
-
module ClassMethods
|
19
|
-
# Lists hash with associations
|
20
|
-
# @return [HashWithIndifferentAccess]
|
21
|
-
def associations
|
22
|
-
self._associations ||= HashWithIndifferentAccess.new
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
# Defines belongs_to association
|
28
|
-
# @param [Symbol] object_name
|
29
|
-
def belongs_to(object_name, options = {})
|
30
|
-
association = Syncano::Model::Association::BelongsTo.new(self, object_name, options)
|
31
|
-
associations[object_name] = association
|
32
|
-
|
33
|
-
define_method(object_name) do
|
34
|
-
association = self.class.associations[object_name]
|
35
|
-
id = send(association.foreign_key)
|
36
|
-
scope = scope_builder(association.associated_model).find(id)
|
37
|
-
end
|
38
|
-
|
39
|
-
define_method("#{object_name}=") do |object|
|
40
|
-
association = self.class.associations[object_name]
|
41
|
-
|
42
|
-
unless object.is_a?(association.associated_model)
|
43
|
-
raise "Object should be an instance of #{association.associated_model} class"
|
44
|
-
end
|
45
|
-
send("#{association.foreign_key}=", object.try(:id))
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Defines has_one association
|
50
|
-
# @param [Symbol] object_name
|
51
|
-
def has_one(object_name, options = {})
|
52
|
-
association = Syncano::Model::Association::HasOne.new(self, object_name, options)
|
53
|
-
associations[object_name] = association
|
54
|
-
|
55
|
-
define_method(object_name) do
|
56
|
-
association = self.class.associations[object_name]
|
57
|
-
|
58
|
-
scope = scope_builder.new(association.associated_model)
|
59
|
-
scope.where("#{association.foreign_key} = ?", id).first if id.present?
|
60
|
-
end
|
61
|
-
|
62
|
-
define_method("#{object_name}=") do |object|
|
63
|
-
association = self.class.associations[object_name]
|
64
|
-
|
65
|
-
unless object.is_a?(association.associated_model)
|
66
|
-
raise "Object should be an instance of #{association.associated_model} class"
|
67
|
-
end
|
68
|
-
|
69
|
-
object.send("#{association.foreign_key}=", id)
|
70
|
-
object.save unless object.new_record?
|
71
|
-
object
|
72
|
-
end
|
73
|
-
|
74
|
-
define_method("build_#{object_name}") do |attributes = {}|
|
75
|
-
association = self.class.associations[object_name]
|
76
|
-
association.associated_model.new(attributes)
|
77
|
-
end
|
78
|
-
|
79
|
-
define_method("create_#{object_name}") do |attributes = {}|
|
80
|
-
association = self.class.associations[object_name]
|
81
|
-
association.associated_model.create(attributes)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Defines has_many association
|
86
|
-
# @param [Symbol] collection_name
|
87
|
-
def has_many(collection_name, options = {})
|
88
|
-
association = Syncano::Model::Association::HasMany.new(self, collection_name, options)
|
89
|
-
associations[collection_name] = association
|
90
|
-
|
91
|
-
define_method(collection_name) do
|
92
|
-
association = self.class.associations[collection_name]
|
93
|
-
association.scope_builder(self)
|
94
|
-
end
|
95
|
-
|
96
|
-
define_method("#{collection_name}=") do |collection|
|
97
|
-
association = self.class.associations[collection_name]
|
98
|
-
objects_ids = {}
|
99
|
-
|
100
|
-
collection.each do |object|
|
101
|
-
"Object should be an instance of #{association.associated_model} class" unless object.is_a?(association.associated_model)
|
102
|
-
objects_ids[object.id] = true
|
103
|
-
end
|
104
|
-
|
105
|
-
send(collection_name).all.each do |object|
|
106
|
-
unless objects_ids[object.id]
|
107
|
-
object.send("#{association.foreign_key}=", nil)
|
108
|
-
object.save unless object.new_record?
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
collection.each do |object|
|
113
|
-
object.send("#{association.foreign_key}=", id)
|
114
|
-
object.save unless object.new_record?
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'syncano/model/scope_builder'
|
2
|
-
|
3
|
-
module Syncano
|
4
|
-
module Model
|
5
|
-
# Module with associations functionality for Syncano::ActiveRecord
|
6
|
-
module Association
|
7
|
-
# Base class for all associations
|
8
|
-
class Base
|
9
|
-
# Constructor for association
|
10
|
-
# @param [Class] source_model
|
11
|
-
# @param [Symbol] name
|
12
|
-
def initialize(source_model, name, options = {})
|
13
|
-
self.source_model = source_model
|
14
|
-
self.associated_model = name.to_s.classify.constantize
|
15
|
-
self.foreign_key = options[:foreign_key] || source_model.name.foreign_key
|
16
|
-
end
|
17
|
-
|
18
|
-
# Checks if association is belongs_to type
|
19
|
-
# @return [FalseClass]
|
20
|
-
def belongs_to?
|
21
|
-
false
|
22
|
-
end
|
23
|
-
|
24
|
-
# Checks if association is has_one type
|
25
|
-
# @return [FalseClass]
|
26
|
-
def has_one?
|
27
|
-
false
|
28
|
-
end
|
29
|
-
|
30
|
-
# Checks if association is has_many type
|
31
|
-
# @return [FalseClass]
|
32
|
-
def has_many?
|
33
|
-
false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'syncano/model/associations/base'
|
2
|
-
|
3
|
-
module Syncano
|
4
|
-
module Model
|
5
|
-
module Association
|
6
|
-
# Class for belongs to association
|
7
|
-
class BelongsTo < Syncano::Model::Association::Base
|
8
|
-
attr_reader :associated_model, :foreign_key, :source_model
|
9
|
-
|
10
|
-
# Constructor for belongs_to association
|
11
|
-
# @param [Class] source_model
|
12
|
-
# @param [Symbol] name
|
13
|
-
def initialize(source_model, name, options = {})
|
14
|
-
super
|
15
|
-
self.foreign_key = options[:foreign_key] || associated_model.name.foreign_key
|
16
|
-
end
|
17
|
-
|
18
|
-
# Checks if association is belongs_to type
|
19
|
-
# @return [TrueClass]
|
20
|
-
def belongs_to?
|
21
|
-
true
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_writer :associated_model, :foreign_key, :source_model
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'syncano/model/associations/base'
|
2
|
-
|
3
|
-
module Syncano
|
4
|
-
module Model
|
5
|
-
module Association
|
6
|
-
# Class for has many association
|
7
|
-
class HasMany < Syncano::Model::Association::Base
|
8
|
-
attr_reader :associated_model, :foreign_key, :source_model
|
9
|
-
|
10
|
-
# Checks if association is has_many type
|
11
|
-
# @return [TrueClass]
|
12
|
-
def has_many?
|
13
|
-
true
|
14
|
-
end
|
15
|
-
|
16
|
-
# Returns new associaton object with source object set
|
17
|
-
# @param [Object] source
|
18
|
-
# @return [Syncano::ActiveRecord::Association::HasMany]
|
19
|
-
def scope_builder(source)
|
20
|
-
association = self.dup
|
21
|
-
association.source = source
|
22
|
-
association
|
23
|
-
end
|
24
|
-
|
25
|
-
# Builds new associated object
|
26
|
-
# @return [Object]
|
27
|
-
def build(attributes = {})
|
28
|
-
new(attributes)
|
29
|
-
end
|
30
|
-
|
31
|
-
def new(attributes = {})
|
32
|
-
associated_model.new(attributes.merge(foreign_key => source.id))
|
33
|
-
end
|
34
|
-
|
35
|
-
# Creates new associated object
|
36
|
-
# @return [Object]
|
37
|
-
def create(attributes = {})
|
38
|
-
associated_model.create(attributes.merge(foreign_key => source.id))
|
39
|
-
end
|
40
|
-
|
41
|
-
# Adds object to the related collection by setting foreign key
|
42
|
-
# @param [Object] object
|
43
|
-
# @return [Object]
|
44
|
-
def <<(object)
|
45
|
-
"Object should be an instance of #{associated_model} class" unless object.is_a?(associated_model)
|
46
|
-
|
47
|
-
object.send("#{foreign_key}=", source.id)
|
48
|
-
object.save unless object.new_record?
|
49
|
-
object
|
50
|
-
end
|
51
|
-
|
52
|
-
protected
|
53
|
-
|
54
|
-
attr_accessor :source
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
attr_writer :associated_model, :foreign_key, :source_model
|
59
|
-
|
60
|
-
# Overwritten method_missing for handling scope methods
|
61
|
-
# @param [String] name
|
62
|
-
# @param [Array] args
|
63
|
-
def method_missing(name, *args)
|
64
|
-
scope_builder = Syncano::Model::ScopeBuilder.new(associated_model).where("#{foreign_key} = ?", source.id)
|
65
|
-
|
66
|
-
if scope_builder.respond_to?(name) || !source.scopes[name].nil?
|
67
|
-
scope_builder.send(name, *args)
|
68
|
-
else
|
69
|
-
super
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|