scaffold_pico 1.1.6 → 1.1.7

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: 05cb9ae933761d5c005549a9b394100a715856d5
4
- data.tar.gz: 55c7e30fb9c60eda9a0d36678e7141f6c291390b
3
+ metadata.gz: 14cf2648944a7e5f17fefee16207c780e92cb932
4
+ data.tar.gz: b42eaf583b52b2b40f507f5833f563a95e7612db
5
5
  SHA512:
6
- metadata.gz: 83426759ac134ba0e6d7bb1289de61b250ec3ed22bb9b0e0d9e67380027d93f03efb726a3d6fe193bd3df93bc39142fdfa25e4e7296015840c1b878241d28af5
7
- data.tar.gz: 3c28e4b8d4238e4b6ab72255c71c3fb71b371922bd85201222e23832c30509bbf98a0414763946f1c492d67ba1ea0a023758e9768f713eb3d2e2fd3dffa9c9a5
6
+ metadata.gz: 5f4addb50eaa34fb870635bc0ecaf30b5b9db09994aa33472daf565301257c3442a4847d933bbc2c14807f4ccb0555855ebd696b9983e4a8b0471565c1bd144b
7
+ data.tar.gz: 78b7b56bf9f28549a31ce8388a92f28b54075a3386bca329d23510933516472cb9aa669a625d4896f806e044353e0aa08345f067587bce088d9d8fb3a637d3fd
@@ -2,20 +2,22 @@ class <%= @rails.resource.search_class_name %>
2
2
  include ActiveModel::Model
3
3
 
4
4
  attr_accessor(
5
- <% @rails.resource.fields.select {|k,v| @rails.controller.search_fields.include?(k) }.each_pair do |field_name, field_type| %>
6
- <% if field_type == 'belongs_to' -%>
7
- :<%= field_name %>_id,
8
- <% else %>
9
- :<%= field_name %>,
5
+ <% @rails.controller.search_fields.map do |field_name| %>
6
+ <%=
7
+ if @rails.resource.fields[field_name] == 'belongs_to'
8
+ ":#{field_name}_id,"
9
+ else
10
+ ":#{field_name},"
11
+ end
12
+ -%>
10
13
  <% end %>
11
- <% end %>
12
14
  )
13
15
 
14
- <% @rails.resource.fields.select {|k,v| @rails.controller.search_fields.include?(k) }.each_pair do |field_name, field_type| %>
15
- <%- if field_type == "integer" %>
16
- validates :<%= field_name -%>, numericality: { only_integer: true }, allow_blank: true
17
- <%- end %>
18
- <%- end %>
16
+ <% @rails.controller.search_fields.select { |search_filed| @rails.resource.fields[search_filed] == 'integer' }.each do |search_filed| %>
17
+ <%=
18
+ "validates :#{field_name}, numericality: { only_integer: true }, allow_blank: true"
19
+ -%>
20
+ <% end %>
19
21
 
20
22
  def initialize *args
21
23
  @relation = <%= @rails.resource.class_name_with_modules %>
@@ -23,25 +25,32 @@ class <%= @rails.resource.search_class_name %>
23
25
  end
24
26
 
25
27
  def results
26
- <%= @rails.resource.name %> = @relation
27
-
28
- <%= @rails.resource.name %> = @relation.order("updated_at") if <%= @rails.resource.class_name_with_modules %>.column_names.include?('updated_at')
28
+ <% resource_name = @rails.resource.name.pluralize %>
29
+ <%= resource_name -%> = @relation
29
30
 
30
31
  if valid?
31
- <% @rails.resource.fields.select {|k,v| @rails.controller.search_fields.include?(k) }.each_pair do |field_name, field_type| %>
32
- <% if ['string', 'text'].include?(field_type) -%>
33
- <%= @rails.resource.name %> = <%= @rails.resource.name %>.where("<%= field_name %> LIKE ?", "%#{<%= field_name %>}%") if self.<%= field_name %>.present?
34
- <% elsif field_type == "boolean" -%>
35
- <%= @rails.resource.name %> = <%= @rails.resource.name %>.where(<%= field_name -%>: <%= field_name -%>=='1') if self.<%= field_name %>.present?
36
- <% elsif field_type == 'belongs_to' -%>
37
- <%= @rails.resource.name %> = <%= @rails.resource.name %>.where(<%= field_name %>_id: <%= field_name %>_id) if self.<%= field_name %>_id.present?
38
- <% else -%>
39
- <%= @rails.resource.name %> = <%= @rails.resource.name %>.where(<%= field_name %>: <%= field_name %>) if self.<%= field_name %>.present?
40
- <% end -%>
41
- <% end -%>
42
- end
32
+ <% @rails.controller.search_fields.each do |field_name| %>
33
+ <%=
34
+ case @rails.resource.fields[field_name]
35
+ when 'string', 'text'
36
+ "#{resource_name} = #{resource_name}.where(\"#{field_name} LIKE ?\", \"%\#{#{field_name}}%\") if #{field_name}.present?"
37
+ when 'boolean'
38
+ "#{resource_name} = #{resource_name}.where(#{field_name}: true) if #{field_name} == '1'"
39
+ when 'belongs_to'
40
+ "#{resource_name} = #{resource_name}.where(#{field_name}_id: #{field_name}_id) if #{field_name}_id.present?"
41
+ when 'int', 'integer'
42
+ "#{resource_name} = #{resource_name}.where(#{field_name}: #{field_name}.to_i) if #{field_name}.present?"
43
+ else
44
+ "#{resource_name} = #{resource_name}.where(#{field_name}: #{field_name}) if #{field_name}.present?"
45
+ end
46
+ -%>
47
+ <% end %>
43
48
 
44
- <%= @rails.resource.name %>
49
+ if <%= @rails.resource.class_name_with_modules -%>.attribute_names.include?('updated_at')
50
+ <%= resource_name %>.order(updated_at: :desc)
51
+ else
52
+ <%= resource_name %>
53
+ end
54
+ end
45
55
  end
46
-
47
56
  end
@@ -1,15 +1,21 @@
1
1
  = form.error_notification
2
2
  .form-inputs
3
- <% @rails.resource.fields.each_pair do |field_name, kind| -%>
4
- <% if kind == 'file' -%>
5
- = form.input :<%= field_name -%>, as: :file
6
- <% elsif kind == 'belongs_to' -%>
7
- = form.association :<%= field_name %>
8
- <% elsif kind == 'text' -%>
9
- = form.input :<%= field_name -%>, as: :text
10
- <% elsif ['date', 'datetime'].include?(kind) -%>
11
- = form.input :<%= field_name -%>, as: :date, html5: true
12
- <% else -%>
13
- = form.input :<%= field_name %>
14
- <% end -%>
15
- <% end -%>
3
+ <% @rails.resource.fields.each_pair do |field_name, kind| %>
4
+ <%- next if field_name == 'id' -%>
5
+ <%=
6
+ case kind
7
+ when 'file'
8
+ "= form.input :#{field_name}, as: :file"
9
+ when 'belongs_to'
10
+ "= form.association :#{field_name}"
11
+ when 'text'
12
+ "= form.input :#{field_name}, as: :text"
13
+ when 'date', 'datetime'
14
+ "= form.input :#{field_name}, as: :date, html5: true"
15
+ when 'boolean'
16
+ "= form.input :#{field_name}, as: :boolean"
17
+ else
18
+ "= form.input :#{field_name}"
19
+ end
20
+ -%>
21
+ <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaffold_pico
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - gudata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-18 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport