controller_scaffolder 0.1.0
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 +7 -0
- data/lib/controller_scaffolder.rb +72 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9037017674a03acb1737448dc3a3e7face8dc32
|
4
|
+
data.tar.gz: 36d42223a310b8b081acacb9d1888041ccf86300
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43cdd75b95ef52823c4acc91c55ade4302eebc1ede12e10cc42d6117efa8a22f20386c3a4ba7c7ab6f17b84ab4536c2e5f2814d3c3e04e0f34e41da4c5365005
|
7
|
+
data.tar.gz: 9915e298e0a8011d81a1c029ac0021e97bad78a8e72bcd7e60a92e1483356cecd143df27a1b280bb24af162b510d75924e368743739d79328532afcb7a8285a8
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ControllerScaffolder
|
2
|
+
|
3
|
+
def scaffold! user_options = {}
|
4
|
+
resource = user_options[:resource] || self.to_s.underscore.split("/").last.split("_")[0..-2].join("_")
|
5
|
+
|
6
|
+
options = {
|
7
|
+
singular: resource.singularize,
|
8
|
+
plural: resource.pluralize,
|
9
|
+
instance_member: "@#{resource.singularize}",
|
10
|
+
instance_collection: "@#{resource.pluralize}",
|
11
|
+
model_name: resource.singularize.camelize
|
12
|
+
}
|
13
|
+
|
14
|
+
options.merge!(user_options)
|
15
|
+
|
16
|
+
class_eval %{
|
17
|
+
before_action :set_#{options[:singular]}, only: [ :show, :edit, :update, :destroy ]
|
18
|
+
|
19
|
+
def index
|
20
|
+
#{options[:instance_collection]} = #{options[:model_name]}.all
|
21
|
+
end
|
22
|
+
|
23
|
+
def show
|
24
|
+
end
|
25
|
+
|
26
|
+
def new
|
27
|
+
#{options[:instance_member]} = #{options[:model_name]}.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit
|
31
|
+
end
|
32
|
+
|
33
|
+
def create
|
34
|
+
#{options[:instance_member]} = #{options[:model_name]}.new(#{options[:singular]}_params)
|
35
|
+
|
36
|
+
if #{options[:instance_member]}.save
|
37
|
+
redirect_to #{options[:instance_member]}, notice: '#{options[:singular].humanize} was successfully created.'
|
38
|
+
else
|
39
|
+
render action: 'new'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
if #{options[:instance_member]}.update(#{options[:singular]}_params)
|
45
|
+
redirect_to #{options[:instance_member]}, notice: '#{options[:singular].humanize} was successfully updated.'
|
46
|
+
else
|
47
|
+
render action: 'edit'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def destroy
|
52
|
+
#{options[:instance_member]}.destroy
|
53
|
+
redirect_to #{options[:plural]}_path, notice: '#{options[:singular].humanize} was successfully destroyed.'
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def set_#{options[:singular]}
|
59
|
+
#{options[:instance_member]} = #{options[:model_name]}.find(params[:id])
|
60
|
+
end
|
61
|
+
|
62
|
+
def #{options[:singular]}_params
|
63
|
+
params.require(:#{options[:singular]}).permit(#{options[:permitted_fields]})
|
64
|
+
end
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
class ActionController::Base
|
71
|
+
extend ::ControllerScaffolder
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: controller_scaffolder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Skiba
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
description: Easily scaffold RESTful controllers
|
28
|
+
email: skiba-alex@ya.ru
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/controller_scaffolder.rb
|
34
|
+
homepage: http://github.com/lacrosse/controller_scaffolder
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.0.3
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Easily scaffold controllers
|
58
|
+
test_files: []
|