adhoc-generators 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 754919abd00031ded4698235eff5f7cf5d323deb
4
- data.tar.gz: 42a455e5fad7083b936b91328fe539d3cc853f8e
3
+ metadata.gz: 41d1e43da9f97728b0ef6e08245f40e87c48a698
4
+ data.tar.gz: 40aef30c65246e320c1985158a1db25e54032c56
5
5
  SHA512:
6
- metadata.gz: ff077bf96bde8106723f0f9dfc601de959b7cd26da5d6ddceb019003f08d23cf8fbbf05d819c81eb8a9b2bafd1f9c5e0b759f784b3f8dc44368ad93dfdca8a4b
7
- data.tar.gz: bad0b54aef752a882012e7e8a5935f7000df73cabddf9e09fe3a969073e7f07d98e2877f745975e850431eda3aa37e8b5733bc2db4d84addb3565f2ee4865c26
6
+ metadata.gz: 6bac520a3f939f6c10b5cd92d9115479d13067ad3cceea220c062b7124f10eb825df58c36be15e2b0fc3bdd71b778b80374bbe6df8aaf75f3f79c8cad1f06ad6
7
+ data.tar.gz: 1dc847e47a9776123fcb5b9ac74a3ad58fa0bf770581760a49e65dda782fbf6f071424bcbd9d55b4b96cf9f4f54cb3a16d8c1020cebd578cccbdcc0fe644b7a1
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- adhoc-generators (0.0.2)
4
+ adhoc-generators (0.0.4)
5
+ paperclip (~> 3.5.1)
5
6
  rails (~> 4.0.0)
6
7
 
7
8
  GEM
@@ -35,6 +36,10 @@ GEM
35
36
  atomic (1.1.13)
36
37
  bcrypt-ruby (3.1.2)
37
38
  builder (3.1.4)
39
+ climate_control (0.0.3)
40
+ activesupport (>= 3.0)
41
+ cocaine (0.5.1)
42
+ climate_control (>= 0.0.3, < 1.0)
38
43
  cucumber (1.3.6)
39
44
  builder (>= 2.1.2)
40
45
  diff-lcs (>= 1.1.3)
@@ -57,6 +62,11 @@ GEM
57
62
  metaclass (~> 0.0.1)
58
63
  multi_json (1.7.9)
59
64
  multi_test (0.0.2)
65
+ paperclip (3.5.1)
66
+ activemodel (>= 3.0.0)
67
+ activesupport (>= 3.0.0)
68
+ cocaine (~> 0.5.0)
69
+ mime-types
60
70
  polyglot (0.3.3)
61
71
  rack (1.5.2)
62
72
  rack-test (0.6.2)
@@ -10,14 +10,9 @@ module Adhoc
10
10
 
11
11
  argument :name, type: :string, default: 'Portfolio', banner: 'PortfolioBanner'
12
12
 
13
- class_option :namespace_model,
14
- desc: 'If the resource is namespaced, include the model in the namespace.',
15
- type: :boolean
16
-
17
13
  def initialize(*args, &block)
18
14
  super
19
15
  print_usage unless name.underscore =~ /^[a-z][a-z0-9_\/]+$/
20
- @namespace_model = options.namespace_model?
21
16
 
22
17
  @attributes = []
23
18
 
@@ -27,22 +22,19 @@ module Adhoc
27
22
 
28
23
  end
29
24
 
30
-
31
25
  def create_model
32
26
  template 'model.rb', "app/models/#{file_name}.rb"
33
27
  end
34
28
 
35
-
36
29
  def create_migration
37
- migration_template 'migration.rb', "db/migrate/create_#{plural_name.gsub('/', '_')}.rb"
30
+ migration_template 'migration.rb', "db/migrate/create_#{table_name}.rb"
38
31
  end
39
32
 
40
-
41
33
  def create_controller
42
34
  template 'controller.rb', "app/controllers/#{plural_name}_controller.rb"
43
35
  template 'helper.rb', "app/helpers/#{plural_name}_helper.rb"
44
36
 
45
- %w[index show new edit].each do |action|
37
+ controller_views.each do |action|
46
38
  template "views/#{action}.html.erb", "app/views/#{plural_name}/#{action}.html.erb"
47
39
  end
48
40
 
@@ -57,50 +49,49 @@ module Adhoc
57
49
  }
58
50
  end
59
51
 
60
-
61
52
  private
62
53
 
63
- def file_name
54
+ def file_name # potfolio
64
55
  name.underscore
65
56
  end
66
57
 
67
- def constant_name
68
- file_name.upcase
58
+ def plural_name # portfolios
59
+ name.underscore.pluralize
69
60
  end
70
61
 
71
- def model_name
72
- file_name.capitalize
62
+ def model_name # Portfolio
63
+ name.underscore.capitalize
73
64
  end
74
65
 
75
- def plural_class_name
66
+ def plural_model_name # Portfolios
76
67
  plural_name.camelize
77
68
  end
78
69
 
79
- def plural_name
80
- file_name.pluralize
81
- end
82
-
83
- def table_name
84
- if name.include?('::') && @namespace_model
70
+ def table_name # portfolios
71
+ if name.include?('::')
85
72
  plural_name.gsub('/', '_')
86
73
  end
87
74
  end
88
75
 
89
76
  def instance_name
90
- file_name.gsub('/','_')
77
+ name.underscore.gsub('/','_')
91
78
  end
92
79
 
93
80
  def instances_name
94
81
  instance_name.pluralize
95
82
  end
96
83
 
84
+ def controller_views
85
+ %w[index show new edit]
86
+ end
87
+
97
88
  def controller_actions
98
89
  %w[index show new edit create update destroy]
99
90
  end
100
91
 
101
- def controller_methods(dir_name)
92
+ def controller_methods
102
93
  controller_actions.map do |action|
103
- read_template("#{dir_name}/#{action}.rb")
94
+ read_template("actions/#{action}.rb")
104
95
  end.join("\n").strip
105
96
  end
106
97
 
@@ -116,54 +107,54 @@ module Adhoc
116
107
  names.all? { |name| action? name }
117
108
  end
118
109
 
119
- def singular_name
120
- name.underscore
121
- end
110
+ def singular_name
111
+ name.underscore
112
+ end
122
113
 
123
- def item_resource
124
- name.underscore.gsub('/','_')
125
- end
114
+ def item_resource
115
+ name.underscore.gsub('/','_')
116
+ end
126
117
 
127
- def items_path
128
- if action? :index
129
- "#{item_resource.pluralize}_path"
130
- else
131
- "root_path"
132
- end
133
- end
118
+ def items_path
119
+ if action? :index
120
+ "#{item_resource.pluralize}_path"
121
+ else
122
+ "root_path"
123
+ end
124
+ end
134
125
 
135
- def item_path(options = {})
136
- name = options[:instance_variable] ? "@#{instance_name}" : instance_name
137
- suffix = options[:full_url] ? "url" : "path"
138
- if options[:action].to_s == "new"
139
- "new_#{item_resource}_#{suffix}"
140
- elsif options[:action].to_s == "edit"
141
- "edit_#{item_resource}_#{suffix}(#{name})"
142
- else
143
- if name.include?('::')
144
- namespace = singular_name.split('/')[0..-2]
145
- "[:#{namespace.join(', :')}, #{name}]"
146
- else
147
- name
126
+ def item_path(options = {})
127
+ name = options[:instance_variable] ? "@#{instance_name}" : instance_name
128
+ suffix = options[:full_url] ? "url" : "path"
129
+ if options[:action].to_s == "new"
130
+ "new_#{item_resource}_#{suffix}"
131
+ elsif options[:action].to_s == "edit"
132
+ "edit_#{item_resource}_#{suffix}(#{name})"
133
+ else
134
+ if name.include?('::')
135
+ namespace = singular_name.split('/')[0..-2]
136
+ "[:#{namespace.join(', :')}, #{name}]"
137
+ else
138
+ name
139
+ end
140
+ end
148
141
  end
149
- end
150
- end
151
142
 
152
- def item_url
153
- if action? :show
154
- item_path(:full_url => true, :instance_variable => true)
155
- else
156
- items_url
157
- end
158
- end
143
+ def item_url
144
+ if action? :show
145
+ item_path(:full_url => true, :instance_variable => true)
146
+ else
147
+ items_url
148
+ end
149
+ end
159
150
 
160
- def items_url
161
- if action? :index
162
- item_resource.pluralize + '_url'
163
- else
164
- "root_url"
165
- end
166
- end
151
+ def items_url
152
+ if action? :index
153
+ item_resource.pluralize + '_url'
154
+ else
155
+ "root_url"
156
+ end
157
+ end
167
158
 
168
159
  def form_partial?
169
160
  actions? :new, :edit
@@ -1,7 +1,7 @@
1
1
  def create
2
- @<%= instance_name %> = <%= model_name %>.new(params[:<%= instance_name %>])
2
+ @<%= instance_name %> = <%= model_name %>.new(<%= instance_name %>_params)
3
3
  if @<%= instance_name %>.save
4
- redirect_to <%= item_url %>, :notice => "Successfully created <%= model_name.underscore.humanize.downcase %>."
4
+ redirect_to <%= item_url %>, notice: "Successfully created <%= model_name.underscore.humanize.downcase %>."
5
5
  else
6
6
  render :new
7
7
  end
@@ -1,5 +1,4 @@
1
1
  def destroy
2
- @<%= instance_name %> = <%= model_name %>.find(params[:id])
3
2
  @<%= instance_name %>.destroy
4
- redirect_to <%= items_url %>, :notice => "Successfully destroyed <%= model_name.underscore.humanize.downcase %>."
3
+ redirect_to <%= items_url %>, notice: "Successfully destroyed <%= model_name.underscore.humanize.downcase %>."
5
4
  end
@@ -1,3 +1,2 @@
1
1
  def edit
2
- @<%= instance_name %> = <%= model_name %>.find(params[:id])
3
2
  end
@@ -1,3 +1,2 @@
1
1
  def show
2
- @<%= instance_name %> = <%= model_name %>.find(params[:id])
3
2
  end
@@ -1,8 +1,7 @@
1
1
  def update
2
- @<%= instance_name %> = <%= model_name %>.find(params[:id])
3
- if @<%= instance_name %>.update_attributes(params[:<%= instance_name %>])
4
- redirect_to <%= item_url %>, :notice => "Successfully updated <%= model_name.underscore.humanize.downcase %>."
2
+ if @<%= instance_name %>.update_attributes(<%= instance_name %>_params)
3
+ redirect_to <%= item_url %>, notice: "Successfully updated <%= model_name.underscore.humanize.downcase %>."
5
4
  else
6
5
  render :edit
7
6
  end
8
- end
7
+ end
@@ -1,3 +1,15 @@
1
- class <%= plural_class_name %>Controller < ApplicationController
2
- <%= controller_methods :actions %>
1
+ class <%= plural_model_name %>Controller < ApplicationController
2
+ before_action :set_<%= instance_name %>, only: [:show, :edit, :update, :destroy]
3
+
4
+ <%= controller_methods %>
5
+
6
+ private
7
+
8
+ def set_<%= instance_name %>
9
+ @<%= instance_name %> = <%= model_name %>.where(id: params[:id]).first
10
+ end
11
+
12
+ def <%= instance_name %>_params
13
+ params.require(:<%= instance_name %>).permit(<%= attributes.map { |a| ":#{a.name}" }.join(", ") %>)
14
+ end
3
15
  end
@@ -1,2 +1,2 @@
1
- module <%= plural_class_name %>Helper
1
+ module <%= plural_model_name %>Helper
2
2
  end
@@ -1,9 +1,10 @@
1
- class Create<%= model_name.pluralize.delete('::') %> < ActiveRecord::Migration
1
+ class Create<%= plural_model_name.delete('::') %> < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :<%= table_name || plural_name.split('/').last %> do |t|
3
+ create_table :<%= plural_name.split('/').last %> do |t|
4
4
  <%- for attribute in attributes -%>
5
5
  t.<%= attribute.type %> :<%= attribute.name %>
6
6
  <%- end -%>
7
+ t.attachment :picture
7
8
  <%- unless options[:skip_timestamps] -%>
8
9
  t.timestamps
9
10
  <%- end -%>
@@ -11,6 +12,6 @@ class Create<%= model_name.pluralize.delete('::') %> < ActiveRecord::Migration
11
12
  end
12
13
 
13
14
  def self.down
14
- drop_table :<%= table_name || plural_name.split('/').last %>
15
+ drop_table :<%= plural_name.split('/').last %>
15
16
  end
16
17
  end
@@ -1,3 +1,5 @@
1
1
  class <%= model_name %> < ActiveRecord::Base
2
2
 
3
+
4
+
3
5
  end
@@ -1,6 +1,6 @@
1
1
  <%% title "<%= singular_name.titleize %>" %>
2
2
 
3
- <%- for attribute in attributes -%>
3
+ <%- attributes.each do |attribute| -%>
4
4
  <p>
5
5
  <strong><%= attribute.human_name.titleize %>:</strong>
6
6
  <%%= @<%= instance_name %>.<%= attribute.name %> %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adhoc-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - folklore
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: paperclip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 3.5.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 3.5.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec-rails
29
43
  requirement: !ruby/object:Gem::Requirement