restly 0.0.1.alpha.8 → 0.0.1.alpha.9
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.
- data/lib/restly.rb +6 -0
- data/lib/restly/associations.rb +2 -2
- data/lib/restly/associations/base/builders.rb +0 -2
- data/lib/restly/associations/base/conditionals.rb +0 -2
- data/lib/restly/associations/base/stubs.rb +7 -3
- data/lib/restly/base/instance.rb +1 -1
- data/lib/restly/embedded_associations/class_methods.rb +3 -3
- data/lib/restly/version.rb +1 -1
- metadata +2 -2
data/lib/restly.rb
CHANGED
@@ -22,6 +22,12 @@ module Restly
|
|
22
22
|
autoload :Client
|
23
23
|
autoload :ConcernedInheritance
|
24
24
|
|
25
|
+
if defined?(Rails::Console)
|
26
|
+
def self.login(username, password)
|
27
|
+
Base.current_token = { access_token: Client.new.password.get_token(username, password).token }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
25
31
|
end
|
26
32
|
|
27
33
|
require 'restly/railtie' if Object.const_defined?('Rails')
|
data/lib/restly/associations.rb
CHANGED
@@ -56,18 +56,18 @@ module Restly::Associations
|
|
56
56
|
private
|
57
57
|
|
58
58
|
def association_attributes
|
59
|
-
@association_attributes ||= {}
|
59
|
+
@association_attributes ||= {}.with_indifferent_access
|
60
60
|
end
|
61
61
|
|
62
62
|
def set_association(attr, val)
|
63
63
|
association = self.class.reflect_on_resource_association(attr)
|
64
64
|
association.valid?(val)
|
65
65
|
association_attributes[attr] = val
|
66
|
+
puts association_attributes
|
66
67
|
end
|
67
68
|
|
68
69
|
def get_association(attr, options={})
|
69
70
|
association = self.class.reflect_on_resource_association(attr)
|
70
|
-
|
71
71
|
if (stubbed = association.stub self, association_attributes[attr]).present?
|
72
72
|
stubbed
|
73
73
|
elsif (loaded = association.load self, options).present?
|
@@ -12,8 +12,6 @@ module Restly::Associations::Base::Builders
|
|
12
12
|
collection? ? association.build_collection(parent) : association.build_instance(parent, attributes)
|
13
13
|
end
|
14
14
|
|
15
|
-
private
|
16
|
-
|
17
15
|
def build_instance(parent, attributes)
|
18
16
|
instance = association_class.new(attributes, options)
|
19
17
|
instance.write_attribute("#{@owner.resource_name}_id", parent.id) if association_class.method_defined?("#{@owner.resource_name}_id")
|
@@ -6,10 +6,14 @@ module Restly::Associations::Base::Stubs
|
|
6
6
|
collection? ? stub_collection(parent, attributes) : stub_instance(parent, attributes)
|
7
7
|
end
|
8
8
|
|
9
|
-
private
|
10
|
-
|
11
9
|
def stub_collection(parent, attributes)
|
12
|
-
collection = attributes.map
|
10
|
+
collection = attributes.map do |item|
|
11
|
+
if item.respond_to? :attributes
|
12
|
+
item
|
13
|
+
else
|
14
|
+
association_class.new(item, loaded: embedded?)
|
15
|
+
end
|
16
|
+
end
|
13
17
|
Restly::Proxies::Associations::Collection.new(collection, parent)
|
14
18
|
end
|
15
19
|
|
data/lib/restly/base/instance.rb
CHANGED
@@ -22,7 +22,7 @@ module Restly::Base::Instance
|
|
22
22
|
@init_options = options
|
23
23
|
@attributes = HashWithIndifferentAccess.new
|
24
24
|
@association_cache = {}
|
25
|
-
@association_attributes = {}
|
25
|
+
@association_attributes = {}.with_indifferent_access
|
26
26
|
@aggregation_cache = {}
|
27
27
|
@attributes_cache = {}
|
28
28
|
@previously_changed = {}
|
@@ -5,7 +5,7 @@ module Restly::EmbeddedAssociations::ClassMethods
|
|
5
5
|
# Embeds One
|
6
6
|
def embeds_resource(name, options = {})
|
7
7
|
exclude_field(name) if ancestors.include?(Restly::Base)
|
8
|
-
self.resource_associations[name] = association = EmbedsOne.new(self, name, options)
|
8
|
+
self.resource_associations[name] = association = Restly::EmbeddedAssociations::EmbedsOne.new(self, name, options)
|
9
9
|
|
10
10
|
define_method name do |options={}|
|
11
11
|
return get_association(name) if get_association(name).present?
|
@@ -21,7 +21,7 @@ module Restly::EmbeddedAssociations::ClassMethods
|
|
21
21
|
# Embeds Many
|
22
22
|
def embeds_resources(name, options = {})
|
23
23
|
exclude_field(name) if ancestors.include?(Restly::Base)
|
24
|
-
self.resource_associations[name] = association = EmbedsMany.new(self, name, options)
|
24
|
+
self.resource_associations[name] = association = Restly::EmbeddedAssociations::EmbedsMany.new(self, name, options)
|
25
25
|
|
26
26
|
define_method name do |options={}|
|
27
27
|
get_association(name, options)
|
@@ -34,7 +34,7 @@ module Restly::EmbeddedAssociations::ClassMethods
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def embedded_in(name, options={})
|
37
|
-
self.resource_associations[name] = association = EmbeddedIn.new(self, name, options)
|
37
|
+
self.resource_associations[name] = association = Restly::EmbeddedAssociations::EmbeddedIn.new(self, name, options)
|
38
38
|
|
39
39
|
define_method name do |options={}|
|
40
40
|
get_association(name, options)
|
data/lib/restly/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.alpha.
|
4
|
+
version: 0.0.1.alpha.9
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|