effective_resources 0.1.1 → 0.2
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 +6 -0
- data/app/controllers/concerns/effective/crud_controller.rb +45 -14
- data/app/helpers/effective_resources_helper.rb +6 -0
- data/app/models/effective/resources/associations.rb +4 -0
- data/app/models/effective/resources/init.rb +2 -0
- data/app/models/effective/resources/klass.rb +1 -1
- data/lib/effective_resources/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: 042a1e7ebafddc560f55cc76c3b4c4271dc53d56
|
4
|
+
data.tar.gz: cd9e12a5646863cac21983f01520b9594a658c86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 041fbf5b5709d5293117f4d88d2f6c389bc4fd8182cd3572b499b520d0e7229e35dd02f3317d59b1e2b40a197b0aa366bd0256566be1b692b956b4cf7ced584f
|
7
|
+
data.tar.gz: 3800490cf26e3ef45fffe0b2ebe59aa99684204d3feaa8f7c3d06295d9c8d7a56d6a04b0031499ff0b28f1ea986380d427feb3549d2c4e3aba98820eebf35fe3
|
data/README.md
CHANGED
@@ -26,6 +26,12 @@ Add to your contoller:
|
|
26
26
|
class PostsController < ApplicationController
|
27
27
|
include Effective::CrudController
|
28
28
|
|
29
|
+
protected
|
30
|
+
|
31
|
+
def post_scope
|
32
|
+
{client_id: current_user.client_id} # Or a symbol
|
33
|
+
end
|
34
|
+
|
29
35
|
def post_params
|
30
36
|
params.require(:post).permit(:id, :title, :body)
|
31
37
|
end
|
@@ -10,12 +10,12 @@ module Effective
|
|
10
10
|
|
11
11
|
def index
|
12
12
|
@page_title ||= resource_plural_name.titleize
|
13
|
-
EffectiveResources.authorized?(self, :index, resource_class)
|
13
|
+
EffectiveResources.authorized?(self, :index, resource_class.new)
|
14
14
|
|
15
15
|
self.resources ||= resource_class.all
|
16
16
|
|
17
17
|
if resource_datatable_class
|
18
|
-
@datatable ||= resource_datatable_class.new(params[:scopes])
|
18
|
+
@datatable ||= resource_datatable_class.new(resource_datatable_attributes, params[:scopes])
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -87,6 +87,15 @@ module Effective
|
|
87
87
|
|
88
88
|
protected
|
89
89
|
|
90
|
+
def resource_redirect_path
|
91
|
+
case params[:commit].to_s
|
92
|
+
when 'Save' ; send(effective_resource.edit_path, resource)
|
93
|
+
when 'Save and Continue' ; send(effective_resource.index_path)
|
94
|
+
when 'Save and Add New' ; send(effective_resource.new_path)
|
95
|
+
else send(effective_resource.show_path, resource)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
90
99
|
def resource # @thing
|
91
100
|
instance_variable_get("@#{resource_name}")
|
92
101
|
end
|
@@ -103,9 +112,7 @@ module Effective
|
|
103
112
|
send(:instance_variable_set, "@#{resource_plural_name}", instance)
|
104
113
|
end
|
105
114
|
|
106
|
-
|
107
|
-
effective_resource.klass
|
108
|
-
end
|
115
|
+
private
|
109
116
|
|
110
117
|
def resource_name # 'thing'
|
111
118
|
effective_resource.name
|
@@ -115,6 +122,35 @@ module Effective
|
|
115
122
|
effective_resource.plural_name
|
116
123
|
end
|
117
124
|
|
125
|
+
# Scoped to resource_scope_method_name
|
126
|
+
def resource_class # Thing
|
127
|
+
@resource_class ||= (
|
128
|
+
if resource_scope_method_name.blank?
|
129
|
+
effective_resource.klass
|
130
|
+
else
|
131
|
+
case (resource_scope = send(resource_scope_method_name))
|
132
|
+
when Hash ; effective_resource.klass.where(resource_scope)
|
133
|
+
when Symbol ; effective_resource.klass.send(resource_scope)
|
134
|
+
when nil ; effective_resource.klass
|
135
|
+
else
|
136
|
+
raise "expected #{resource_scope_method_name} to return a Hash or Symbol"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
def resource_datatable_attributes
|
143
|
+
return {} unless resource_scope_method_name.present?
|
144
|
+
|
145
|
+
case (resource_scope = send(resource_scope_method_name))
|
146
|
+
when Hash ; resource_scope
|
147
|
+
when Symbol ; {resource_scope: true}
|
148
|
+
when nil ; {}
|
149
|
+
else
|
150
|
+
raise "expected #{resource_scope_method_name} to return a Hash or Symbol"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
118
154
|
def resource_datatable_class # ThingsDatatable
|
119
155
|
effective_resource.datatable_klass
|
120
156
|
end
|
@@ -123,17 +159,12 @@ module Effective
|
|
123
159
|
["#{resource_name}_params", "#{resource_plural_name}_params", 'permitted_params'].find { |name| respond_to?(name, true) } || 'params'
|
124
160
|
end
|
125
161
|
|
126
|
-
def
|
127
|
-
|
162
|
+
def resource_scope_method_name
|
163
|
+
["#{resource_name}_scope", "#{resource_plural_name}_scope", 'resource_scope', 'default_scope'].find { |name| respond_to?(name, true) }
|
128
164
|
end
|
129
165
|
|
130
|
-
def
|
131
|
-
|
132
|
-
when 'Save' ; send(effective_resource.edit_path, resource)
|
133
|
-
when 'Save and Continue' ; send(effective_resource.index_path)
|
134
|
-
when 'Save and Add New' ; send(effective_resource.new_path)
|
135
|
-
else send(effective_resource.show_path, resource)
|
136
|
-
end
|
166
|
+
def resource_index_path
|
167
|
+
effective_resource.index_path
|
137
168
|
end
|
138
169
|
|
139
170
|
private
|
@@ -3,10 +3,14 @@ module Effective
|
|
3
3
|
module Associations
|
4
4
|
|
5
5
|
def belong_tos
|
6
|
+
return [] unless klass
|
7
|
+
|
6
8
|
@belong_tos ||= klass.reflect_on_all_associations(:belongs_to)
|
7
9
|
end
|
8
10
|
|
9
11
|
def nested_resources
|
12
|
+
return {} unless klass
|
13
|
+
|
10
14
|
@nested ||= klass.reflect_on_all_autosave_associations.inject({}) do |hash, reference|
|
11
15
|
hash[reference] = Effective::Resource.new(reference); hash
|
12
16
|
end
|
@@ -25,6 +25,8 @@ module Effective
|
|
25
25
|
@written_belong_tos = []
|
26
26
|
@written_scopes = []
|
27
27
|
|
28
|
+
return unless File.exists?(model_file)
|
29
|
+
|
28
30
|
Effective::CodeReader.new(model_file) do |reader|
|
29
31
|
first = reader.index { |line| line == '# Attributes' }
|
30
32
|
last = reader.index(from: first) { |line| line.start_with?('#') == false && line.length > 0 } if first
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|