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: e40cb927580081fb976d84220cc33e0e636345df
4
- data.tar.gz: 5fca21fc95f40f2df1ae2add3af2807cb6ffce97
3
+ metadata.gz: 9e93bb313cafc6d56845d6aa323617b9e0fe9a51
4
+ data.tar.gz: 4a6395bb956e5882affbb856eb53f95df157934f
5
5
  SHA512:
6
- metadata.gz: 661bfda0de1d8e558e008a05f4c23da19a5e5478342a71af3c52eb596ffaf3c6fbe7d4424b0e7bc324ed44e628f1390382e987122fa4d9c1f7582f69c532e836
7
- data.tar.gz: 1df187a0f3e592fd2d01c6416eea13fa2441c1634a26ef67000620b1dc11a33bc647ef0b4f26b0ce663ab9d9cd9905a4cf27c77e3fc0c93cb3a5a8cb43c36f60
6
+ metadata.gz: 3036554128dced8f6e0ee0b7b15a2ad15d85233551a98e2490903fd3eb4bf2d1e777360c1bdcb92ecee236ecf0e23c267b4ebf7ecc54232aedf24ff8ce2cdf94
7
+ data.tar.gz: 61b72b5e8fadfe481793e45e6e271dceb46ba84edc8bfc2c52be8728e51428494a9f842b163727d58e7e1baa40c7faeb857f17d0f21bb619ed459cb88c42ac30
@@ -10,18 +10,15 @@ module Scaffold
10
10
  :route_resource_name,
11
11
  :services_folder
12
12
 
13
- def expand_default_types hash
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(<%= @fields.keys.collect{|field| ":#{field}"}.join(', ') %>)
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(<%= @fields.keys.collect{|field| ":#{field}"}.join(', ') %>)
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(:company) do
2
+ Fabricator(:<%= @resource_name %>) do
3
3
  <% else %>
4
- Fabricator(:company, class_name: '<%= @modulized_resource_class_name -%>') do
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' -%>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaffold_pico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - gudata