rails-rapido 0.3.2 → 0.3.3
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/app/views/rapido/app/index.slim +2 -1
- data/app/views/rapido/app/new.slim +1 -0
- data/app/views/rapido/app/show.slim +3 -0
- data/lib/rapido/app_controller.rb +5 -2
- data/lib/rapido/controller.rb +30 -10
- data/lib/rapido/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca32937003fab6959385c900d1fdc932944ec353
|
4
|
+
data.tar.gz: 5f3c3f531a06425f60450498f1901fc7408ebc57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98cde731a822eb1c3071f3c910d6ca73f0ab60263a65ce60f3c3dd98213a2a169825eb5fb511353ff2f78ce060f42105d5103e4fef331ad23c6e82cf1825d595
|
7
|
+
data.tar.gz: a139dd6fb0fe5a694433ba90afc432b813484c3988e6b2764bf19a000a3b1576ca9a59c0d1947db0f21f4d660d99cee2dda802f8b832819372587f1cdf249090
|
@@ -1,4 +1,4 @@
|
|
1
|
-
h2= [@owner
|
1
|
+
h2= [@owner&.name, @resource_class.name.capitalize.pluralize].compact.join(" ")
|
2
2
|
= link_to "New #{@resource_class.name.capitalize}", @new_path
|
3
3
|
table
|
4
4
|
thead
|
@@ -11,4 +11,5 @@ table
|
|
11
11
|
- if index == 0
|
12
12
|
td= link_to resource.name, url_for([@owner, resource].compact)
|
13
13
|
- else
|
14
|
+
- next if resource.name == resource[key]
|
14
15
|
td= resource[key]
|
@@ -11,6 +11,7 @@ module Rapido
|
|
11
11
|
before_action do
|
12
12
|
resource_permitted_params
|
13
13
|
end
|
14
|
+
helper_method :owned_resources
|
14
15
|
end
|
15
16
|
|
16
17
|
def index
|
@@ -22,7 +23,7 @@ module Rapido
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def new
|
25
|
-
@resource =
|
26
|
+
@resource = resource_base.send(resource_class_name.pluralize).new
|
26
27
|
end
|
27
28
|
|
28
29
|
def create
|
@@ -36,7 +37,9 @@ module Rapido
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def destroy
|
39
|
-
resource.destroy
|
40
|
+
unless resource.destroy
|
41
|
+
flash[:error] = resource.errors.full_messages.join('. ')
|
42
|
+
end
|
40
43
|
redirect_to after_delete_path(resource)
|
41
44
|
end
|
42
45
|
|
data/lib/rapido/controller.rb
CHANGED
@@ -13,6 +13,10 @@ module Rapido
|
|
13
13
|
@authority_getter = sym.to_sym
|
14
14
|
end
|
15
15
|
|
16
|
+
def belongs_to_nothing!
|
17
|
+
@belongs_to_nothing = true
|
18
|
+
end
|
19
|
+
|
16
20
|
def belongs_to(sym, opts = {})
|
17
21
|
@owner_class = sym.to_sym
|
18
22
|
return @owner_getter = opts[:getter] if opts[:getter]
|
@@ -25,6 +29,11 @@ module Rapido
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
32
|
+
def has_many(sym)
|
33
|
+
@owned_resources ||= []
|
34
|
+
@owned_resources << sym
|
35
|
+
end
|
36
|
+
|
28
37
|
def owner_lookup_defaults
|
29
38
|
owner_lookup_param(@owner_class, :id)
|
30
39
|
owner_lookup_field(:id)
|
@@ -67,7 +76,8 @@ module Rapido
|
|
67
76
|
if setting(:free_from_authority)
|
68
77
|
nil
|
69
78
|
else
|
70
|
-
send(setting(:authority_getter)
|
79
|
+
send(setting(:authority_getter) ||
|
80
|
+
self.class.superclass.instance_variable_get(:@authority_getter))
|
71
81
|
end
|
72
82
|
end
|
73
83
|
end
|
@@ -87,13 +97,13 @@ module Rapido
|
|
87
97
|
end
|
88
98
|
|
89
99
|
def build_resource
|
90
|
-
|
100
|
+
resource_base.send(resource_class_name.pluralize).new(resource_params)
|
91
101
|
end
|
92
102
|
|
93
103
|
def resource_collection
|
94
104
|
@resource_collection ||= begin
|
95
|
-
raise RecordNotFound unless owner
|
96
|
-
|
105
|
+
raise RecordNotFound unless setting(:belongs_to_nothing) || owner
|
106
|
+
resource_base.send(resource_class_name.pluralize).page(params[:page])
|
97
107
|
end
|
98
108
|
end
|
99
109
|
|
@@ -122,7 +132,9 @@ module Rapido
|
|
122
132
|
|
123
133
|
def owner
|
124
134
|
@owner ||= begin
|
125
|
-
if setting(:
|
135
|
+
if setting(:belongs_to_nothing)
|
136
|
+
nil
|
137
|
+
elsif setting(:owner_getter)
|
126
138
|
send(setting(:owner_getter))
|
127
139
|
else
|
128
140
|
if setting(:free_from_authority)
|
@@ -137,13 +149,17 @@ module Rapido
|
|
137
149
|
end
|
138
150
|
end
|
139
151
|
|
152
|
+
def resource_base
|
153
|
+
setting(:belongs_to_nothing) ? authority : owner
|
154
|
+
end
|
155
|
+
|
140
156
|
def resource
|
141
157
|
@resource ||= begin
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
158
|
+
resource_base
|
159
|
+
.send(resource_class_name.pluralize)
|
160
|
+
.find_by!(resource_lookup_param => params[resource_lookup_param])
|
161
|
+
rescue ActiveRecord::RecordNotFound
|
162
|
+
raise RecordNotFound
|
147
163
|
end
|
148
164
|
end
|
149
165
|
|
@@ -166,6 +182,10 @@ module Rapido
|
|
166
182
|
self.class.name.split('::')[-1].remove('Controller').singularize.underscore
|
167
183
|
end
|
168
184
|
|
185
|
+
def owned_resources
|
186
|
+
@owned_resources ||= setting(:owned_resources) || []
|
187
|
+
end
|
188
|
+
|
169
189
|
def setting(var)
|
170
190
|
self.class.instance_variable_get("@#{var}")
|
171
191
|
end
|
data/lib/rapido/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-rapido
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Kirst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kaminari
|