base10-first-floor 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.
- data/VERSION.yml +4 -0
- data/lib/action_controller/first_floor.rb +108 -0
- data/test/first_floor_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +58 -0
data/VERSION.yml
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
class ActionController::FirstFloor < ActionController::Base
|
|
2
|
+
def index
|
|
3
|
+
obj_class = controller_name.to_s.singularize.titleize
|
|
4
|
+
view_obj = controller_name.to_s
|
|
5
|
+
eval( "@#{view_obj} = obj_class.constantize.find(:all)" )
|
|
6
|
+
render_response( eval( "@#{view_obj}" ), 'index' )
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def show
|
|
10
|
+
obj_class = controller_name.to_s.singularize.titleize
|
|
11
|
+
view_obj = controller_name.to_s.singularize
|
|
12
|
+
eval( "@#{view_obj} = obj_class.constantize.find(params[:id])" )
|
|
13
|
+
render_response( eval( "@#{view_obj}" ) , 'show' )
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def new
|
|
17
|
+
obj_class = controller_name.to_s.singularize.titleize
|
|
18
|
+
view_obj = controller_name.to_s.singularize
|
|
19
|
+
eval( "@#{view_obj} = obj_class.constantize.new" )
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create
|
|
23
|
+
obj_class = controller_name.to_s.singularize.titleize
|
|
24
|
+
obj_name = controller_name.to_s.singularize
|
|
25
|
+
@obj = obj_class.constantize.new(params[obj_name.to_sym])
|
|
26
|
+
if @obj.save
|
|
27
|
+
flash[:notice] = "#{obj_class} was successfully created"
|
|
28
|
+
flash[:status] = 201
|
|
29
|
+
redirect_to :action => :index
|
|
30
|
+
else
|
|
31
|
+
eval( "@#{obj_name} = @obj" )
|
|
32
|
+
|
|
33
|
+
flash[:notice] = "Cannot create this #{obj_class}. There were some errors."
|
|
34
|
+
flash[:status] = 400
|
|
35
|
+
render_response( eval( "@#{obj_name}" ), 'new', 400 )
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def edit
|
|
40
|
+
obj_class = controller_name.to_s.singularize.titleize
|
|
41
|
+
view_obj = controller_name.to_s.singularize
|
|
42
|
+
|
|
43
|
+
eval( "@#{view_obj} = obj_class.constantize.find(params[:id])" )
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def update
|
|
47
|
+
obj_class = controller_name.to_s.singularize.titleize
|
|
48
|
+
obj_name = controller_name.to_s.singularize
|
|
49
|
+
@obj = obj_class.constantize.find(params[:id])
|
|
50
|
+
|
|
51
|
+
if @obj.update_attributes( params[obj_name.to_sym] )
|
|
52
|
+
check_validation(@obj)
|
|
53
|
+
|
|
54
|
+
flash[:notice] = "#{obj_class} was successfully updated."
|
|
55
|
+
flash[:status] = 200
|
|
56
|
+
eval( "@#{obj_name} = @obj" )
|
|
57
|
+
redirect_to :action => :show, :id => eval( "@#{obj_name}" )
|
|
58
|
+
else
|
|
59
|
+
eval( "@#{obj_name} = @obj" )
|
|
60
|
+
|
|
61
|
+
flash[:notice] = "#{obj_class} had some errors and was not updated."
|
|
62
|
+
flash[:status] = 400
|
|
63
|
+
render_response( eval( "@#{obj_name}" ), 'edit', 400 )
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def destroy
|
|
68
|
+
obj_class = controller_name.to_s.singularize.titleize
|
|
69
|
+
obj = obj_class.constantize.find(params[:id])
|
|
70
|
+
obj_info = nil
|
|
71
|
+
|
|
72
|
+
if obj.respond_to?(:name)
|
|
73
|
+
obj_info = "#{obj.id}:#{obj.name}"
|
|
74
|
+
else
|
|
75
|
+
obj_info = "#{obj.id}:#{obj.to_s}"
|
|
76
|
+
end
|
|
77
|
+
obj_class.constantize.delete(params[:id])
|
|
78
|
+
flash[:notice] = "#{obj_class} '#{obj_info} successfully deleted.'"
|
|
79
|
+
redirect_to :action => 'index'
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def render_response(obj, tmpl, status = :ok)
|
|
83
|
+
klass = nil
|
|
84
|
+
if obj.class == Array
|
|
85
|
+
klass = obj[0].class
|
|
86
|
+
|
|
87
|
+
## Make sure we're not dealing with a NilClass, which we don't have
|
|
88
|
+
## a template for. Default to the controller class.
|
|
89
|
+
if klass == NilClass
|
|
90
|
+
klass = controller_name.to_s.singularize.titleize
|
|
91
|
+
end
|
|
92
|
+
else
|
|
93
|
+
klass = obj.class
|
|
94
|
+
end
|
|
95
|
+
namespace = klass.to_s.downcase.pluralize
|
|
96
|
+
if /^Admin/.match( self.class.to_s )
|
|
97
|
+
namespace = "admin/#{namespace}"
|
|
98
|
+
end
|
|
99
|
+
respond_to do |format|
|
|
100
|
+
format.html { render :template => "#{namespace}/#{tmpl}.html.erb",
|
|
101
|
+
:status => status }
|
|
102
|
+
format.xml { render :xml => obj.to_xml, :status => status }
|
|
103
|
+
format.json { render :json => obj.to_json, :status => status }
|
|
104
|
+
format.yaml { render :text => obj.to_yaml, :status => status }
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: base10-first-floor
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nathan L. Walls
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-01-30 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: TODO
|
|
17
|
+
email: nathan@rexluther.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- VERSION.yml
|
|
26
|
+
- lib/action_controller
|
|
27
|
+
- lib/action_controller/first_floor.rb
|
|
28
|
+
- test/first_floor_test.rb
|
|
29
|
+
- test/test_helper.rb
|
|
30
|
+
has_rdoc: true
|
|
31
|
+
homepage: http://github.com/base10/first-floor
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options:
|
|
34
|
+
- --inline-source
|
|
35
|
+
- --charset=UTF-8
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: "0"
|
|
43
|
+
version:
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: "0"
|
|
49
|
+
version:
|
|
50
|
+
requirements: []
|
|
51
|
+
|
|
52
|
+
rubyforge_project:
|
|
53
|
+
rubygems_version: 1.2.0
|
|
54
|
+
signing_key:
|
|
55
|
+
specification_version: 2
|
|
56
|
+
summary: A little bit above ActionController::Base
|
|
57
|
+
test_files: []
|
|
58
|
+
|