first-floor 0.1.2 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Nathan L. Walls
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,43 @@
1
+ first-floor
2
+ ===========
3
+
4
+ An extension for ActionController::Base. I'm lazy and am tired of:
5
+
6
+ - Updating controller code to do what I want for every project
7
+ - Copying the same controller centralization code between projects. It's not
8
+ DRY. Eventually, things that aren't DRY begin to smell.
9
+
10
+ So, what am I doing here?
11
+
12
+ This gem defines ActionController::FirstFloor, which inherits
13
+ ActionController::Base
14
+
15
+ It defines the following common REST methods:
16
+ * index
17
+ * show
18
+ * new
19
+ * create
20
+ * edit
21
+ * update
22
+ * destroy
23
+
24
+ It also defines render_response, which takes an object, a template name and
25
+ an optional status. The seven methods utilize render_response to
26
+ render a response. HTML, JSON, XML and YAML are supported. The extension of
27
+ the request will determine the response format. Template names are presumed
28
+ to be the method named itself. Objects used within the templates are
29
+ assumed to be the object name. For instance, you have object Foo.
30
+
31
+ * An index will return @foos
32
+ * show will use @foo
33
+
34
+ In my workflow, I generate model and controller with rspec's generator, and
35
+ then can rip out the guts of the generated controllers in favor of FirstFloor.
36
+
37
+ My next step is, of course, improving my project generation process.
38
+
39
+
40
+ COPYRIGHT
41
+ =========
42
+
43
+ Copyright (c) 2009 Rex Luther Corporation. See LICENSE for details.
@@ -0,0 +1,41 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = "first-floor"
9
+ s.summary = %Q{A little bit above ActionController::Base}
10
+ s.email = "nathan@wallscorp.us"
11
+ s.homepage = "http://github.com/base10/first-floor"
12
+ s.description = %Q{Takes care of the basic seven CRUD controller methods against HTML, XML, JSON and YAML. This was very useful with Rails 2.x. Under Rails 3 and later, this isn't quite as necessary, since rendering became a lot easier.}
13
+ s.authors = ["Nathan L. Walls"]
14
+ s.license = 'MIT'
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ Rake::TestTask.new do |t|
22
+ t.libs << 'lib'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ Rake::RDocTask.new do |rdoc|
28
+ rdoc.rdoc_dir = 'rdoc'
29
+ rdoc.title = 'first-floor'
30
+ rdoc.options << '--line-numbers' << '--inline-source'
31
+ rdoc.rdoc_files.include('README*')
32
+ rdoc.rdoc_files.include('lib/**/*.rb')
33
+ end
34
+
35
+ # Rcov::RcovTask.new do |t|
36
+ # t.libs << 'test'
37
+ # t.test_files = FileList['test/**/*_test.rb']
38
+ # t.verbose = true
39
+ # end
40
+
41
+ #task :default => :rcov
@@ -1,5 +1,5 @@
1
- ---
1
+ ---
2
2
  :major: 0
3
- :minor: 1
3
+ :minor: 2
4
+ :patch: 0
4
5
  :build:
5
- :patch: 2
@@ -0,0 +1,45 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "first-floor"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nathan L. Walls"]
12
+ s.date = "2012-02-12"
13
+ s.description = "Takes care of the basic seven CRUD controller methods against HTML, XML, JSON and YAML. This was very useful with Rails 2.x. Under Rails 3 and later, this isn't quite as necessary, since rendering became a lot easier."
14
+ s.email = "nathan@wallscorp.us"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "doc/FirstFloor_ideas.oo3/contents.xml",
25
+ "first-floor.gemspec",
26
+ "lib/action_controller/first_floor.rb",
27
+ "test/first_floor_test.rb",
28
+ "test/test_helper.rb"
29
+ ]
30
+ s.homepage = "http://github.com/base10/first-floor"
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = "1.8.15"
34
+ s.summary = "A little bit above ActionController::Base"
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ else
41
+ end
42
+ else
43
+ end
44
+ end
45
+
@@ -29,7 +29,7 @@ class ActionController::FirstFloor < ActionController::Base
29
29
  redirect_to :action => :index
30
30
  else
31
31
  eval( "@#{obj_name} = @obj" )
32
-
32
+
33
33
  flash[:notice] = "Cannot create this #{obj_class}. There were some errors."
34
34
  flash[:status] = 400
35
35
  render_response( eval( "@#{obj_name}" ), 'new', 400 )
@@ -39,7 +39,7 @@ class ActionController::FirstFloor < ActionController::Base
39
39
  def edit
40
40
  obj_class = controller_name.to_s.singularize.titleize
41
41
  view_obj = controller_name.to_s.singularize
42
-
42
+
43
43
  eval( "@#{view_obj} = obj_class.constantize.find(params[:id])" )
44
44
  end
45
45
 
@@ -47,33 +47,33 @@ class ActionController::FirstFloor < ActionController::Base
47
47
  obj_class = controller_name.to_s.singularize.titleize
48
48
  obj_name = controller_name.to_s.singularize
49
49
  @obj = obj_class.constantize.find(params[:id])
50
-
50
+
51
51
  if @obj.update_attributes( params[obj_name.to_sym] )
52
52
  check_validation(@obj)
53
-
53
+
54
54
  flash[:notice] = "#{obj_class} was successfully updated."
55
55
  flash[:status] = 200
56
56
  eval( "@#{obj_name} = @obj" )
57
57
  redirect_to :action => :show, :id => eval( "@#{obj_name}" )
58
58
  else
59
59
  eval( "@#{obj_name} = @obj" )
60
-
60
+
61
61
  flash[:notice] = "#{obj_class} had some errors and was not updated."
62
62
  flash[:status] = 400
63
63
  render_response( eval( "@#{obj_name}" ), 'edit', 400 )
64
- end
64
+ end
65
65
  end
66
66
 
67
67
  def destroy
68
68
  obj_class = controller_name.to_s.singularize.titleize
69
69
  obj = obj_class.constantize.find(params[:id])
70
70
  obj_info = nil
71
-
71
+
72
72
  if obj.respond_to?(:name)
73
73
  obj_info = "#{obj.id}:#{obj.name}"
74
74
  else
75
75
  obj_info = "#{obj.id}:#{obj.to_s}"
76
- end
76
+ end
77
77
  obj_class.constantize.delete(params[:id])
78
78
  flash[:notice] = "#{obj_class} '#{obj_info} successfully deleted.'"
79
79
  redirect_to :action => 'index'
@@ -83,14 +83,14 @@ class ActionController::FirstFloor < ActionController::Base
83
83
  klass = nil
84
84
  if obj.class == Array
85
85
  klass = obj[0].class
86
-
86
+
87
87
  ## Make sure we're not dealing with a NilClass, which we don't have
88
88
  ## a template for. Default to the controller class.
89
89
  if klass == NilClass
90
90
  klass = controller_name.to_s.singularize.titleize
91
- end
91
+ end
92
92
  else
93
- klass = obj.class
93
+ klass = obj.class
94
94
  end
95
95
 
96
96
  namespace = klass.to_s.downcase.pluralize
@@ -100,16 +100,16 @@ class ActionController::FirstFloor < ActionController::Base
100
100
  end
101
101
 
102
102
  respond_to do |format|
103
- format.html { render :template => "#{namespace}/#{tmpl}.html.erb",
103
+ format.html { render :template => "#{namespace}/#{tmpl}",
104
104
  :status => status }
105
105
  format.xml { render :xml => obj.to_xml, :status => status }
106
106
  format.json { render :json => obj.to_json, :status => status }
107
- format.yaml { render :text => obj.to_yaml, :status => status }
107
+ format.yaml { render :text => obj.to_yaml, :status => status }
108
108
  end
109
109
  end
110
110
 
111
111
  protected
112
- def check_validation(obj)
112
+ def check_validation(obj)
113
113
  unless obj.valid?
114
114
  raise ActiveRecord::ActiveRecordError, "This record is invalid."
115
115
  end
metadata CHANGED
@@ -1,59 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: first-floor
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Nathan L. Walls
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-02-22 00:00:00 -05:00
13
- default_executable:
12
+ date: 2012-02-12 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
- description: A gem to DRY out controller code. It lives just a bit above 'ActionController::Base'
17
- email: nathan@rexluther.com
14
+ description: Takes care of the basic seven CRUD controller methods against HTML, XML,
15
+ JSON and YAML. This was very useful with Rails 2.x. Under Rails 3 and later, this
16
+ isn't quite as necessary, since rendering became a lot easier.
17
+ email: nathan@wallscorp.us
18
18
  executables: []
19
-
20
19
  extensions: []
21
-
22
- extra_rdoc_files: []
23
-
24
- files:
20
+ extra_rdoc_files:
21
+ - LICENSE
22
+ - README
23
+ files:
24
+ - LICENSE
25
+ - README
26
+ - Rakefile
25
27
  - VERSION.yml
28
+ - doc/FirstFloor_ideas.oo3/contents.xml
29
+ - first-floor.gemspec
26
30
  - lib/action_controller/first_floor.rb
27
31
  - test/first_floor_test.rb
28
32
  - test/test_helper.rb
29
- has_rdoc: true
30
33
  homepage: http://github.com/base10/first-floor
31
- licenses: []
32
-
34
+ licenses:
35
+ - MIT
33
36
  post_install_message:
34
- rdoc_options:
35
- - --inline-source
36
- - --charset=UTF-8
37
- require_paths:
37
+ rdoc_options: []
38
+ require_paths:
38
39
  - lib
39
- required_ruby_version: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: "0"
44
- version:
45
- required_rubygems_version: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: "0"
50
- version:
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
51
52
  requirements: []
52
-
53
53
  rubyforge_project:
54
- rubygems_version: 1.3.5
54
+ rubygems_version: 1.8.15
55
55
  signing_key:
56
- specification_version: 2
56
+ specification_version: 3
57
57
  summary: A little bit above ActionController::Base
58
58
  test_files: []
59
-