proxima 0.1.5 → 0.2.0
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/lib/proxima/model.rb +54 -32
- data/lib/proxima/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '081e653fe66cc7ffbd3535a48fee5d3c4146ab81'
|
4
|
+
data.tar.gz: b171427373e9544991aba53e5b934376a4f58850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14aef58da59e38ef4b4f285cee5e68d4ceff0e0c472df0a523c8a9b8917f9dd21a0ada2391d204467ce21889d1d6fae1d889189f3c22aa754e9a242c3e12eb09
|
7
|
+
data.tar.gz: 4414e6d9d63b35bf2da37564e05c33827541764395d99ad4dc61c036725f3ecd4ce8e9759a45729919da9af961457c5c50f1a024f9754f1788ee1f4012f33b3a
|
data/lib/proxima/model.rb
CHANGED
@@ -32,41 +32,59 @@ module Proxima
|
|
32
32
|
@api
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.response
|
36
|
+
@response
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.responses
|
40
|
+
@responses || []
|
41
|
+
end
|
42
|
+
|
35
43
|
def self.create(record)
|
36
|
-
|
37
|
-
|
38
|
-
|
44
|
+
if record.is_a? Array
|
45
|
+
models = []
|
46
|
+
@responses = []
|
47
|
+
record.each do |record|
|
48
|
+
model = self.create record
|
49
|
+
@responses.push(model.response)
|
50
|
+
models.push(model) if model
|
51
|
+
end
|
52
|
+
return models
|
53
|
+
end
|
54
|
+
|
55
|
+
model = self.new(record)
|
56
|
+
save_ok = model.save
|
57
|
+
@response = model.response
|
58
|
+
|
59
|
+
return nil unless save_ok
|
39
60
|
model
|
40
61
|
end
|
41
62
|
|
42
63
|
def self.find(query = {}, opts = {})
|
43
64
|
opts[:query] = self.convert_query_or_delta_to_json query
|
44
|
-
response
|
45
|
-
|
46
|
-
return [] unless response.code == 200
|
65
|
+
@response = self.api.get self.find_path.call(query), opts
|
47
66
|
|
48
|
-
|
49
|
-
|
50
|
-
model = self.new
|
51
|
-
model.from_json record
|
52
|
-
model.new_record = false
|
53
|
-
model
|
67
|
+
if @response.code != 200
|
68
|
+
return []
|
54
69
|
end
|
70
|
+
|
71
|
+
models = self.from_json @response.body
|
72
|
+
models.each { |model| model.new_record = false }
|
55
73
|
end
|
56
74
|
|
57
75
|
def self.find_one(query = {}, opts = {})
|
58
|
-
query['$limit'] = 1
|
76
|
+
query['$limit'] = 1
|
59
77
|
self.find(query, opts)[0]
|
60
78
|
end
|
61
79
|
|
62
80
|
def self.count(query = {}, opts = {})
|
63
81
|
query['$limit'] = 0
|
64
82
|
opts[:query] = self.convert_query_or_delta_to_json query
|
65
|
-
response
|
83
|
+
@response = self.api.get self.find_path.call(query), opts
|
66
84
|
|
67
|
-
return nil unless response.code == 200
|
85
|
+
return nil unless @response.code == 200
|
68
86
|
|
69
|
-
response.headers[:x_total_count] || 0
|
87
|
+
@response.headers[:x_total_count] || 0
|
70
88
|
end
|
71
89
|
|
72
90
|
def self.find_by_id(id, query = {}, opts = {})
|
@@ -76,12 +94,12 @@ module Proxima
|
|
76
94
|
end
|
77
95
|
|
78
96
|
query[:id] = id
|
79
|
-
response
|
97
|
+
@response = self.api.get self.find_by_id_path.call(query), opts
|
80
98
|
|
81
|
-
return nil unless response.code == 200
|
99
|
+
return nil unless @response.code == 200
|
82
100
|
|
83
101
|
model = self.new
|
84
|
-
model.from_json response.body
|
102
|
+
model.from_json @response.body
|
85
103
|
model.new_record = false
|
86
104
|
model
|
87
105
|
end
|
@@ -110,17 +128,21 @@ module Proxima
|
|
110
128
|
clear_changes_information unless val
|
111
129
|
end
|
112
130
|
|
131
|
+
def response
|
132
|
+
@response
|
133
|
+
end
|
134
|
+
|
113
135
|
def save(options = {})
|
114
136
|
return false unless self.valid?
|
115
137
|
|
116
138
|
if self.new_record?
|
117
|
-
path
|
118
|
-
payload
|
119
|
-
response = self.class.api.post path, payload
|
139
|
+
path = self.class.create_path.call self.to_h
|
140
|
+
payload = { json: self.as_json(options) }
|
141
|
+
@response = self.class.api.post path, payload
|
120
142
|
|
121
|
-
return false unless response.code == 201
|
143
|
+
return false unless @response.code == 201
|
122
144
|
|
123
|
-
self.from_json response.body, options[:include_root]
|
145
|
+
self.from_json @response.body, options[:include_root]
|
124
146
|
self.new_record = false
|
125
147
|
return true
|
126
148
|
end
|
@@ -128,11 +150,11 @@ module Proxima
|
|
128
150
|
return true if self.persisted?
|
129
151
|
|
130
152
|
options[:flatten] = true if options[:flatten] == nil
|
131
|
-
path
|
132
|
-
payload
|
133
|
-
response = self.class.api.put path, payload
|
153
|
+
path = self.class.update_by_id_path.call self.to_h
|
154
|
+
payload = { json: self.as_json(options) }
|
155
|
+
@response = self.class.api.put path, payload
|
134
156
|
|
135
|
-
return false unless response.code == 204
|
157
|
+
return false unless @response.code == 204
|
136
158
|
self.persisted = true
|
137
159
|
end
|
138
160
|
|
@@ -147,18 +169,18 @@ module Proxima
|
|
147
169
|
def destroy
|
148
170
|
return false if new_record?
|
149
171
|
|
150
|
-
response = self.class.api.delete(self.class.delete_by_id_path.call(self.to_h))
|
172
|
+
@response = self.class.api.delete(self.class.delete_by_id_path.call(self.to_h))
|
151
173
|
|
152
|
-
return false unless response.code == 204
|
174
|
+
return false unless @response.code == 204
|
153
175
|
self.persisted = true
|
154
176
|
end
|
155
177
|
|
156
178
|
def restore
|
157
179
|
return false if new_record?
|
158
180
|
|
159
|
-
response = self.class.api.post(self.class.restore_by_id_path.call(self.to_h))
|
181
|
+
@response = self.class.api.post(self.class.restore_by_id_path.call(self.to_h))
|
160
182
|
|
161
|
-
return false unless response.code == 204
|
183
|
+
return false unless @response.code == 204
|
162
184
|
self.persisted = true
|
163
185
|
end
|
164
186
|
end
|
data/lib/proxima/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxima
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Hurst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.5.
|
134
|
+
rubygems_version: 2.5.2
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: REST Models for Ruby on Rails
|