nube 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nube/base.rb +2 -2
- data/lib/nube/controllers/nube_controller.rb +1 -1
- data/lib/nube/remote_relation.rb +86 -87
- data/lib/nube/remote_scope.rb +1 -1
- data/lib/nube/version.rb +1 -1
- metadata +7 -7
data/lib/nube/base.rb
CHANGED
@@ -98,7 +98,7 @@ module Nube
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def self.do_request(method, site_options, params={})
|
101
|
-
site = site(site_options[:identity], self.name.pluralize.underscore, site_options[:action], site_options[:id])
|
101
|
+
site = site(site_options[:identity], self.name.split('::').last.pluralize.underscore, site_options[:action], site_options[:id])
|
102
102
|
url = URI.parse(site)
|
103
103
|
req = "Net::HTTP::#{method.to_s.camelize}".constantize.new(url.to_s)
|
104
104
|
req.body = params.to_param
|
@@ -129,7 +129,7 @@ module Nube
|
|
129
129
|
|
130
130
|
def self.method_missing(name, *args, &block)
|
131
131
|
super(name, *args) unless ("#{self.name}Relation".constantize.instance_methods - self.instance_methods).include?(name)
|
132
|
-
args.empty? ? self.node.send(name) : self.node.send(name, args
|
132
|
+
args.empty? ? self.node.send(name) : self.node.send(name, *args)
|
133
133
|
end
|
134
134
|
|
135
135
|
end
|
@@ -38,7 +38,7 @@ module NubeController
|
|
38
38
|
|
39
39
|
def self.resource(xmodel); @@resource = xmodel; end
|
40
40
|
|
41
|
-
def apply_relations; @resource = @resource.where(relations).where(params[:server_id]); end
|
41
|
+
def apply_relations; @resource = @resource.where(relations).where(server_id: params[:server_id]); end
|
42
42
|
|
43
43
|
def parse_request; @json = JSON.parse(request.body.read); end
|
44
44
|
|
data/lib/nube/remote_relation.rb
CHANGED
@@ -3,123 +3,122 @@ module RemoteRelation
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
eval("class #{self.to_s}Relation;end")
|
7
|
+
"#{self.to_s}Relation".constantize.class_eval do
|
8
|
+
attr_accessor :xmodel, :params
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def find(*ids)
|
16
|
-
@params.merge!({ where: [{id: ids.flatten}] })
|
17
|
-
resources = all
|
18
|
-
(resources.size > 1) ? resources : resources.first
|
19
|
-
end
|
10
|
+
def initialize(xmodel, params={})
|
11
|
+
@params = params
|
12
|
+
@xmodel = xmodel
|
13
|
+
end
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
def find(*ids)
|
16
|
+
@params.merge!({ where: [{id: ids.flatten}] })
|
17
|
+
resources = all
|
18
|
+
(resources.size > 1) ? resources : resources.first
|
19
|
+
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
def controller_name
|
22
|
+
@xmodel.name.pluralize.underscore
|
23
|
+
end
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
changes[attrib] = (value ? 1 : 0) if !!value == value
|
33
|
-
end
|
34
|
-
@xmodel.put(@params.delete(:site_options).merge({ action: 'update_all' }), { changes: changes, where: [where].flatten }).first
|
35
|
-
end
|
25
|
+
def destroy_all(where={}, relations={})
|
26
|
+
@xmodel.delete(@params.delete(:site_options).merge({ action: 'destroy_all' }), { where: [where].flatten }).map{|attrs| @xmodel.new(attrs, false) }
|
27
|
+
end
|
36
28
|
|
37
|
-
|
38
|
-
|
29
|
+
def update_all(changes={}, where={}, relations={})
|
30
|
+
changes.each do |attrib, value|
|
31
|
+
# change true and false by 1 or 0 becouse params are sent as string
|
32
|
+
changes[attrib] = (value ? 1 : 0) if !!value == value
|
39
33
|
end
|
34
|
+
@xmodel.put(@params.delete(:site_options).merge({ action: 'update_all' }), { changes: changes, where: [where].flatten }).first
|
35
|
+
end
|
40
36
|
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
def empty_attributes
|
38
|
+
@xmodel.get(@params.delete(:site_options).merge({ action: 'empty_attributes' })).first
|
39
|
+
end
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
def count
|
42
|
+
@xmodel.get(@params.delete(:site_options).merge({ action: 'count' }), @params).first.to_i
|
43
|
+
end
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
all.first
|
53
|
-
end
|
45
|
+
def all
|
46
|
+
@xmodel.get(@params.delete(:site_options), @params).map{|attributes| @xmodel.new(attributes, false) }
|
47
|
+
end
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
49
|
+
def first
|
50
|
+
(@params[:order] ||= []) << { id: :asc }
|
51
|
+
@params[:limit] = 1
|
52
|
+
all.first
|
53
|
+
end
|
60
54
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
raise 'Errors: Some class is not Remote Resource'
|
67
|
-
end
|
68
|
-
end
|
55
|
+
def last
|
56
|
+
(@params[:order] ||= []) << { id: :desc }
|
57
|
+
@params[:limit] = 1
|
58
|
+
all.last
|
59
|
+
end
|
69
60
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
61
|
+
def joins(*models)
|
62
|
+
if @xmodel.same_class?(models)
|
63
|
+
params[:joins]= [] unless params.has_key?(:joins)
|
64
|
+
tap{ |s| s.params[:joins] += models }
|
65
|
+
else
|
66
|
+
raise 'Errors: Some class is not Remote Resource'
|
74
67
|
end
|
68
|
+
end
|
75
69
|
|
76
|
-
|
70
|
+
def create(attrs={})
|
71
|
+
obj = @xmodel.new(attrs)
|
72
|
+
obj.save
|
73
|
+
obj
|
74
|
+
end
|
77
75
|
|
78
|
-
|
76
|
+
def where(conditions); tap{|s| (s.params[:where] || s.params[:where] = []) << conditions}; end
|
79
77
|
|
80
|
-
|
78
|
+
def order(conditions); tap{|s| (s.params[:order] || s.params[:order] = []) << conditions}; end
|
81
79
|
|
82
|
-
|
80
|
+
def limit(number); tap{|s| s.params[:limit] = number }; end
|
83
81
|
|
84
|
-
|
85
|
-
@page = size
|
86
|
-
limit(25) unless @params.has_key?(:limit)
|
87
|
-
calculate_offset
|
88
|
-
end
|
82
|
+
def offset(number); tap{|s| s.params[:offset] = number }; end
|
89
83
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
84
|
+
def page(size=1)
|
85
|
+
@page = size
|
86
|
+
limit(25) unless @params.has_key?(:limit)
|
87
|
+
calculate_offset
|
88
|
+
end
|
95
89
|
|
96
|
-
|
90
|
+
def per(size=25)
|
91
|
+
@page ||= 1
|
92
|
+
limit(size)
|
93
|
+
calculate_offset
|
94
|
+
end
|
97
95
|
|
98
|
-
|
99
|
-
value.has_key?(:page) ? page(value[:page]) : page
|
100
|
-
value.has_key?(:per_page) ? per(value[:per_page]) : per
|
101
|
-
end
|
96
|
+
def calculate_offset; offset(@params[:limit] * (@page - 1)); end
|
102
97
|
|
103
|
-
|
98
|
+
def paginate(value={})
|
99
|
+
value.has_key?(:page) ? page(value[:page]) : page
|
100
|
+
value.has_key?(:per_page) ? per(value[:per_page]) : per
|
101
|
+
end
|
104
102
|
|
105
|
-
|
103
|
+
def search(params={}); tap{|s| s.params[:search] = params }; end
|
106
104
|
|
107
|
-
|
108
|
-
@xmodel.send(method, @params.delete(:site_options).merge({ action: action }), @params.merge(transaction: transaction))
|
109
|
-
end
|
105
|
+
alias_method :ransack, :search
|
110
106
|
|
111
|
-
|
107
|
+
def massive_transactions(transaction, method, action)
|
108
|
+
@xmodel.send(method, @params.delete(:site_options).merge({ action: action }), @params.merge(transaction: transaction))
|
109
|
+
end
|
112
110
|
|
113
|
-
|
111
|
+
def massive_creation(transaction); massive_transactions(transaction, 'post', 'massive_creation', site_options); end
|
114
112
|
|
115
|
-
|
113
|
+
def massive_sum(transaction); massive_transactions(transaction, 'put', 'massive_sum', site_options); end
|
116
114
|
|
117
|
-
|
118
|
-
all.send(name, *args, &block)
|
119
|
-
end
|
115
|
+
def massive_update(transaction); massive_transactions(transaction, 'put', 'massive_update', site_options); end
|
120
116
|
|
117
|
+
def method_missing(name, *args, &block)
|
118
|
+
all.send(name, *args, &block)
|
121
119
|
end
|
122
|
-
|
120
|
+
|
121
|
+
end
|
123
122
|
end
|
124
123
|
|
125
124
|
# module ClassMethods
|
data/lib/nube/remote_scope.rb
CHANGED
@@ -7,7 +7,7 @@ module RemoteScope
|
|
7
7
|
|
8
8
|
def node(identity=nil)
|
9
9
|
# identity = IDENTITY_SITE if not identity and defined?(IDENTITY_SITE)
|
10
|
-
"#{self}Relation".constantize.new(self, { site_options: {identity: identity} })
|
10
|
+
"#{self}Relation".constantize.new(self, { site_options: {identity: (identity || token)} })
|
11
11
|
end
|
12
12
|
|
13
13
|
def build_params keys, values
|
data/lib/nube/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- g.edera
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: exe
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2016-04
|
19
|
+
date: 2016-07-04 00:00:00 -03:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 352077850
|
31
31
|
segments:
|
32
32
|
- 4
|
33
33
|
- x
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 352077850
|
46
46
|
segments:
|
47
47
|
- 4
|
48
48
|
- x
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - ~>
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
60
|
+
hash: 352077850
|
61
61
|
segments:
|
62
62
|
- 4
|
63
63
|
- x
|