scaffold_pico 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e93bb313cafc6d56845d6aa323617b9e0fe9a51
|
4
|
+
data.tar.gz: 4a6395bb956e5882affbb856eb53f95df157934f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3036554128dced8f6e0ee0b7b15a2ad15d85233551a98e2490903fd3eb4bf2d1e777360c1bdcb92ecee236ecf0e23c267b4ebf7ecc54232aedf24ff8ce2cdf94
|
7
|
+
data.tar.gz: 61b72b5e8fadfe481793e45e6e271dceb46ba84edc8bfc2c52be8728e51428494a9f842b163727d58e7e1baa40c7faeb857f17d0f21bb619ed459cb88c42ac30
|
data/lib/scaffold/params.rb
CHANGED
@@ -10,18 +10,15 @@ module Scaffold
|
|
10
10
|
:route_resource_name,
|
11
11
|
:services_folder
|
12
12
|
|
13
|
-
|
14
|
-
hash.each_pair do |key, value|
|
15
|
-
hash[key] = 'string' if value.blank?
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize choice
|
13
|
+
def initialize choice
|
20
14
|
(@modules, @model_name) = parse_model(choice[:model]) # what came from the params (it contain namespaces)
|
21
15
|
|
22
16
|
@fields = expand_default_types(hasherize_fields(choice[:fields]))
|
23
17
|
@index_fields = choice[:index_fields].blank? ? @fields.keys : choice[:index_fields]
|
24
18
|
@search_fields = choice[:search_fields].blank? ? @fields.keys : choice[:search_fields]
|
19
|
+
# permitted params
|
20
|
+
@fields_permitted = associations_to_ids(@fields)
|
21
|
+
@search_fields_permitted = search_fields_permitted(@search_fields, @fields)
|
25
22
|
|
26
23
|
@joins = choice[:joins]
|
27
24
|
@includes = choice[:includes]
|
@@ -127,5 +124,33 @@ module Scaffold
|
|
127
124
|
fields
|
128
125
|
end
|
129
126
|
|
127
|
+
|
128
|
+
def expand_default_types hash
|
129
|
+
hash.each_pair do |key, value|
|
130
|
+
hash[key] = 'string' if value.blank?
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# convert company => company_id
|
135
|
+
def associations_to_ids hash
|
136
|
+
to_ids = {}
|
137
|
+
hash.each_pair do |key, type|
|
138
|
+
key_name = ['references', 'belongs_to'].include?(type.downcase) ? "#{key}_id" : key
|
139
|
+
to_ids[key_name] = type
|
140
|
+
end
|
141
|
+
to_ids
|
142
|
+
end
|
143
|
+
|
144
|
+
# convert company => company_id
|
145
|
+
def search_fields_permitted search_fields, fields
|
146
|
+
to_ids = []
|
147
|
+
search_fields.each do |key|
|
148
|
+
next unless fields.keys.include?(key)
|
149
|
+
type = fields[key]
|
150
|
+
to_ids << (['references', 'belongs_to'].include?(type.downcase) ? "#{key}_id" : key)
|
151
|
+
end
|
152
|
+
to_ids
|
153
|
+
end
|
154
|
+
|
130
155
|
end
|
131
156
|
end
|
@@ -61,12 +61,12 @@ class <%= @controller_class_name %> < <%= @base_controller %>
|
|
61
61
|
|
62
62
|
private
|
63
63
|
def <%= @collection_name %>_params
|
64
|
-
params[:<%= @resource_name %>].permit(<%= @
|
64
|
+
params[:<%= @resource_name %>].permit(<%= @fields_permitted.keys.map{|field| ":#{field}"}.join(', ') %>)
|
65
65
|
end
|
66
66
|
|
67
67
|
def search_<%= @collection_name %>_params
|
68
68
|
return {} if params[:<%= @collection_name %>_search].blank?
|
69
|
-
params[:<%= @collection_name %>_search].permit(<%= @
|
69
|
+
params[:<%= @collection_name %>_search].permit(<%= @search_fields_permitted.collect{|field| ":#{field}"}.join(', ') %>)
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<% if @modules.empty? %>
|
2
|
-
Fabricator(
|
2
|
+
Fabricator(:<%= @resource_name %>) do
|
3
3
|
<% else %>
|
4
|
-
Fabricator(
|
4
|
+
Fabricator(:<%= @resource_name %>, class_name: '<%= @modulized_resource_class_name -%>') do
|
5
5
|
<% end -%>
|
6
6
|
<% @fields.each_pair do |field_name, kind| -%>
|
7
7
|
<% if kind == 'belongs_to' -%>
|