decent_ham 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 +4 -4
- data/lib/generators/decent_ham/decent_ham_generator.rb +70 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbaa2c10c45232794ad60500cfa11e91da75f296
|
4
|
+
data.tar.gz: 948b4ec68d35d653e838c4715109c0229174f9c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac8998325ca358256ca2a76d93798ed32bac60de4a1252ab2019c9bdcb4f40e1889d84fb6c7884b2e3481d7257185bd3fa42fadd323beeaa540e7abf31deefac
|
7
|
+
data.tar.gz: 62da2f3acd578d131d87f882ab2b47f18e17449319cdcab8415df01f1054caf9f6324a89ccf71ccf2676a8a4bf163b217f07cab407240e0f812050c2bfb41ffd
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module DecentHam
|
4
|
+
class DecentHamGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def singular_name
|
8
|
+
name.singularize
|
9
|
+
end
|
10
|
+
|
11
|
+
def plural_name
|
12
|
+
name
|
13
|
+
end
|
14
|
+
|
15
|
+
def strong_params
|
16
|
+
strong_params = ":#{singular_name}_params"
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_model
|
20
|
+
template "model.rb", "app/models/#{singular_name}.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
def model_attributes
|
24
|
+
constant_name.columns_hash.map do |key, value|
|
25
|
+
OpenStruct.new(name: key, data_type: value.type)
|
26
|
+
end.delete_if { |column| %w(id created_at updated_at).include? column.name }
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_controller
|
30
|
+
@attributes = model_attributes
|
31
|
+
template "controller.rb", "app/controllers/#{name}_controller.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_route
|
35
|
+
route "resources :#{name}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def constant_name
|
39
|
+
singular_name.capitalize.constantize
|
40
|
+
end
|
41
|
+
|
42
|
+
def attach_form_fields
|
43
|
+
model_attributes.each do |attribute|
|
44
|
+
attribute.form_field =
|
45
|
+
case attribute.data_type
|
46
|
+
when :string || :decimal || :integer || :float || :references
|
47
|
+
"f.text_field :#{attribute.name}"
|
48
|
+
when :text
|
49
|
+
"f.text_area :#{attribute.name}"
|
50
|
+
when :datetime || :timestamp
|
51
|
+
"f.datetime_select :#{attribute.name}"
|
52
|
+
when :boolean
|
53
|
+
"f.check_box :#{attribute.name}"
|
54
|
+
when :date
|
55
|
+
"f.date_select :#{attribute.name}"
|
56
|
+
when :time
|
57
|
+
"f.time_select :#{attribute.name}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_views
|
63
|
+
@attributes = attach_form_fields
|
64
|
+
%w(index new edit _form show).each do |view_name|
|
65
|
+
template "#{view_name}.html.haml", "app/views/#{name}/#{view_name}.html.haml"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decent_ham
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vic Ramon
|
@@ -58,6 +58,7 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- lib/generators/decent_ham/decent_ham_generator.rb
|
61
62
|
- lib/generators/decent_ham/templates/_form.html.haml
|
62
63
|
- lib/generators/decent_ham/templates/controller.rb
|
63
64
|
- lib/generators/decent_ham/templates/edit.html.haml
|