easier-instance-variable-access 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/.gitignore +2 -0
  2. data/.yardopts +1 -0
  3. data/{easier-instance-variable-access/LICENSE → LICENSE} +4 -2
  4. data/README.markdown +44 -0
  5. data/{easier-instance-variable-access/easier-instance-variable-access.gemspec → easier-instance-variable-access.gemspec} +9 -5
  6. data/lib/cody_robbins/easier_instance_variable_access.rb +28 -0
  7. data/{easier-instance-variable-access/lib → lib}/easier-instance-variable-access.rb +0 -0
  8. metadata +16 -45
  9. data/classifyize-1.0.gem +0 -0
  10. data/classifyize/LICENSE +0 -8
  11. data/classifyize/classifyize.gemspec +0 -15
  12. data/classifyize/lib/classifyize.rb +0 -6
  13. data/classifyize/lib/cody_robbins/classifyize.rb +0 -7
  14. data/classifyize/spec/classifyize_spec.rb +0 -7
  15. data/easier-instance-variable-access/lib/cody_robbins/easier_instance_variable_access.rb +0 -18
  16. data/easier-instance-variable-access/spec/easier_instance_variable_access_spec.rb +0 -44
  17. data/http-error/Gemfile +0 -4
  18. data/http-error/Gemfile.lock +0 -86
  19. data/http-error/LICENSE +0 -8
  20. data/http-error/README +0 -48
  21. data/http-error/http-error.gemspec +0 -13
  22. data/http-error/lib/cody_robbins/http_error/instance_methods.rb +0 -14
  23. data/http-error/lib/cody_robbins/http_error/railtie.rb +0 -13
  24. data/http-error/lib/http-error.rb +0 -2
  25. data/http-error/spec/http_error_spec.rb +0 -28
  26. data/http-error/spec/spec_helper.rb +0 -17
  27. data/lookup-record/LICENSE +0 -8
  28. data/lookup-record/lib/cody_robbins/lookup_record/class_methods.rb +0 -19
  29. data/lookup-record/lib/cody_robbins/lookup_record/railtie.rb +0 -11
  30. data/lookup-record/lib/lookup-record.rb +0 -2
  31. data/lookup-record/lookup-record.gemspec +0 -17
  32. data/lookup-record/spec/lookup_record_spec.rb +0 -77
@@ -0,0 +1,2 @@
1
+ .yardoc
2
+ doc
@@ -0,0 +1 @@
1
+ --charset UTF-8 --markup markdown lib/**/*.rb - LICENSE
@@ -1,7 +1,9 @@
1
1
  The MIT License
2
- Copyright © 2011 Cody Robbins
2
+ ===============
3
3
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software“), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+ © 2011 Cody Robbins
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
7
 
6
8
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
9
 
@@ -0,0 +1,44 @@
1
+ Easier Instance Variable Access
2
+ ===============================
3
+
4
+ Ruby’s built-in [`Object#instance_variable_get`](http://ruby-doc.org/core/classes/Object.html#M001028) and [`#instance_variable_set`](http://ruby-doc.org/core/classes/Object.html#M001029) methods are clunky to use because you have to unnecessarily prepend an ‘@’ to the name of the instance variable you pass in—which usually leads to much less readable code in the contexts in which I tend to use these methods. On top of that, they’re poorly named: the method names don’t read like English.
5
+
6
+ This gem adds two methods to `Object` that fix these problems: `instance_variable` method to replace `instance_variable_get` and `set_instance_variable` method to replace `instance_variable_set`.
7
+
8
+ Full documentation is at [RubyDoc.info](http://rubydoc.info/gems/easier-instance-variable-access).
9
+
10
+ Examples
11
+ --------
12
+
13
+ These methods are only available within an instance of a class—like the corresponding built-in Ruby methods—so the following examples are given in that context.
14
+
15
+ ### The usual Ruby way
16
+
17
+ instance_variable_get('@user')
18
+ instance_variable_set('@user', new_value)
19
+
20
+ name = :user
21
+ instance_variable_get("@#{name}")
22
+ instance_variable_set("@#{name}", new_value)
23
+
24
+ ### Using `easier-instance-variable-access`
25
+
26
+ instance_variable(:user)
27
+ set_instance_variable(:user, new_value)
28
+
29
+ name = :user
30
+ instance_variable(name)
31
+ set_instance_variable(name, new_value)
32
+
33
+ Tested with
34
+ -----------
35
+
36
+ * Ruby 1.9.2-p180 — 20 May 2011.
37
+
38
+ Credits
39
+ -------
40
+
41
+ © 2011 [Cody Robbins](http://codyrobbins.com/)
42
+
43
+ * [Homepage](http://codyrobbins.com/software/easier-instance-variable-access)
44
+ * [Follow me on Twitter](http://twitter.com/codyrobbins)
@@ -1,13 +1,17 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'easier-instance-variable-access'
3
- s.version = '1.0'
4
- s.summary = 'Access instance variables in Ruby the way you should be able to'
3
+ s.version = '1.1'
4
+ s.summary = 'Access instance variables in Ruby the way you should be able to.'
5
5
  s.homepage = 'http://codyrobbins.com/software/easier-instance-variable-access'
6
6
  s.author = 'Cody Robbins'
7
7
  s.email = 'cody@codyrobbins.com'
8
8
 
9
- s.post_install_message = 'Please follow me on Twitter!
10
- http://twitter.com/codyrobbins'
9
+ s.post_install_message = '
10
+ -------------------------------------------------------------
11
+ Follow me on Twitter: http://twitter.com/codyrobbins
12
+ -------------------------------------------------------------
11
13
 
12
- s.files = Dir['**/*']
14
+ '
15
+
16
+ s.files = `git ls-files`.split
13
17
  end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+
3
+ module CodyRobbins
4
+ module EasierInstanceVariableAccess
5
+ # Returns the value of the specified instance variable, just like `Object#instance_variable_get`.
6
+ #
7
+ # @return The value of the specified instance variable.
8
+ # @param name [Symbol, String] The name of the instance variable to retrieve—without the leading ‘@’.
9
+ def instance_variable(name)
10
+ instance_variable_get(instance_variable_name(name))
11
+ end
12
+ alias :get_instance_variable :instance_variable
13
+
14
+ # Sets the value of the specified instance variable, just like `Object#instance_variable_set`.
15
+ #
16
+ # @param name [Symbol, String] The name of the instance variable to set—without the leading ‘@’.
17
+ # @param value The value to set the specified instance variable to.
18
+ def set_instance_variable(name, value)
19
+ instance_variable_set(instance_variable_name(name), value)
20
+ end
21
+
22
+ protected
23
+
24
+ def instance_variable_name(name)
25
+ "@#{name}"
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easier-instance-variable-access
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- version: "1.0"
4
+ prerelease:
5
+ version: "1.1"
10
6
  platform: ruby
11
7
  authors:
12
8
  - Cody Robbins
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-05-20 00:00:00 -04:00
13
+ date: 2011-05-23 00:00:00 -04:00
18
14
  default_executable:
19
15
  dependencies: []
20
16
 
@@ -27,40 +23,21 @@ extensions: []
27
23
  extra_rdoc_files: []
28
24
 
29
25
  files:
30
- - classifyize/classifyize.gemspec
31
- - classifyize/lib/classifyize.rb
32
- - classifyize/lib/cody_robbins/classifyize.rb
33
- - classifyize/LICENSE
34
- - classifyize/spec/classifyize_spec.rb
35
- - classifyize-1.0.gem
36
- - easier-instance-variable-access/easier-instance-variable-access.gemspec
37
- - easier-instance-variable-access/lib/cody_robbins/easier_instance_variable_access.rb
38
- - easier-instance-variable-access/lib/easier-instance-variable-access.rb
39
- - easier-instance-variable-access/LICENSE
40
- - easier-instance-variable-access/spec/easier_instance_variable_access_spec.rb
41
- - http-error/Gemfile
42
- - http-error/Gemfile.lock
43
- - http-error/http-error.gemspec
44
- - http-error/lib/cody_robbins/http_error/instance_methods.rb
45
- - http-error/lib/cody_robbins/http_error/railtie.rb
46
- - http-error/lib/http-error.rb
47
- - http-error/LICENSE
48
- - http-error/README
49
- - http-error/spec/http_error_spec.rb
50
- - http-error/spec/spec_helper.rb
51
- - lookup-record/lib/cody_robbins/lookup_record/class_methods.rb
52
- - lookup-record/lib/cody_robbins/lookup_record/railtie.rb
53
- - lookup-record/lib/lookup-record.rb
54
- - lookup-record/LICENSE
55
- - lookup-record/lookup-record.gemspec
56
- - lookup-record/spec/lookup_record_spec.rb
26
+ - .gitignore
27
+ - .yardopts
28
+ - LICENSE
29
+ - README.markdown
30
+ - easier-instance-variable-access.gemspec
31
+ - lib/cody_robbins/easier_instance_variable_access.rb
32
+ - lib/easier-instance-variable-access.rb
57
33
  has_rdoc: true
58
34
  homepage: http://codyrobbins.com/software/easier-instance-variable-access
59
35
  licenses: []
60
36
 
61
- post_install_message: |-
62
- Please follow me on Twitter!
63
- http://twitter.com/codyrobbins
37
+ post_install_message: "\n\
38
+ -------------------------------------------------------------\n\
39
+ Follow me on Twitter: http://twitter.com/codyrobbins\n\
40
+ -------------------------------------------------------------\n\n"
64
41
  rdoc_options: []
65
42
 
66
43
  require_paths:
@@ -70,25 +47,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
47
  requirements:
71
48
  - - ">="
72
49
  - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
50
  version: "0"
77
51
  required_rubygems_version: !ruby/object:Gem::Requirement
78
52
  none: false
79
53
  requirements:
80
54
  - - ">="
81
55
  - !ruby/object:Gem::Version
82
- hash: 3
83
- segments:
84
- - 0
85
56
  version: "0"
86
57
  requirements: []
87
58
 
88
59
  rubyforge_project:
89
- rubygems_version: 1.3.7
60
+ rubygems_version: 1.6.2
90
61
  signing_key:
91
62
  specification_version: 3
92
- summary: Access instance variables in Ruby the way you should be able to
63
+ summary: Access instance variables in Ruby the way you should be able to.
93
64
  test_files: []
94
65
 
Binary file
@@ -1,8 +0,0 @@
1
- The MIT License
2
- Copyright © 2011 Cody Robbins
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software“), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,15 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'classifyize'
3
- s.version = '1.0'
4
- s.summary = 'Get a class from a symbol or string of its name in one fell swoop'
5
- s.homepage = 'http://codyrobbins.com/software/classifyize'
6
- s.author = 'Cody Robbins'
7
- s.email = 'cody@codyrobbins.com'
8
-
9
- s.post_install_message = 'Please follow me on Twitter!
10
- http://twitter.com/codyrobbins'
11
-
12
- s.files = Dir['**/*']
13
-
14
- s.add_dependency('activesupport')
15
- end
@@ -1,6 +0,0 @@
1
- require('cody_robbins/classifyize')
2
-
3
- [[Symbol, CodyRobbins::Classifyize],
4
- [ActiveSupport::Inflector, CodyRobbins::Classifyize]].each do |target, library|
5
- target.send(:include, library)
6
- end
@@ -1,7 +0,0 @@
1
- module CodyRobbins
2
- module Classifyize
3
- def classifyize
4
- to_s.classify.constantize
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- require('spec_helper')
2
-
3
- describe CodyRobbins::Classifyize do
4
- it 'returns a constantized class' do
5
- :object.classifyize.should == Object
6
- end
7
- end
@@ -1,18 +0,0 @@
1
- module CodyRobbins
2
- module EasierInstanceVariableAccess
3
- def get_instance_variable(name)
4
- instance_variable_get(instance_variable_name(name))
5
- end
6
- alias :instance_variable :get_instance_variable
7
-
8
- def set_instance_variable(name, value)
9
- instance_variable_set(instance_variable_name(name), value)
10
- end
11
-
12
- protected
13
-
14
- def instance_variable_name(name)
15
- "@#{name}"
16
- end
17
- end
18
- end
@@ -1,44 +0,0 @@
1
- require('spec_helper')
2
-
3
- describe CodyRobbins::EasierInstanceVariableAccess do
4
- class Dummy
5
- attr_reader(:variable)
6
-
7
- def initialize
8
- @variable = 'Value'
9
- end
10
-
11
- def get_with_get_instance_variable
12
- get_instance_variable(:variable)
13
- end
14
-
15
- def get_with_instance_variable
16
- instance_variable(:variable)
17
- end
18
-
19
- def set(value)
20
- set_instance_variable(:variable, value)
21
- end
22
- end
23
-
24
- let(:dummy) { Dummy.new }
25
-
26
- describe '#get_instance_variable' do
27
- it 'returns the instance variable' do
28
- dummy.get_with_get_instance_variable.should == 'Value'
29
- end
30
- end
31
-
32
- describe '#instance_variable' do
33
- it 'returns the instance variable' do
34
- dummy.get_with_instance_variable.should == 'Value'
35
- end
36
- end
37
-
38
- describe '#set_instance_variable' do
39
- it 'sets the instance variable' do
40
- dummy.set('New value')
41
- dummy.variable.should == 'New value'
42
- end
43
- end
44
- end
@@ -1,4 +0,0 @@
1
- source('http://rubygems.org')
2
-
3
- gem('rails', '3.0.5')
4
- gem('rspec-rails')
@@ -1,86 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.5)
6
- actionpack (= 3.0.5)
7
- mail (~> 2.2.15)
8
- actionpack (3.0.5)
9
- activemodel (= 3.0.5)
10
- activesupport (= 3.0.5)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.4)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.13)
16
- rack-test (~> 0.5.7)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.5)
19
- activesupport (= 3.0.5)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.4)
22
- activerecord (3.0.5)
23
- activemodel (= 3.0.5)
24
- activesupport (= 3.0.5)
25
- arel (~> 2.0.2)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.5)
28
- activemodel (= 3.0.5)
29
- activesupport (= 3.0.5)
30
- activesupport (3.0.5)
31
- arel (2.0.10)
32
- builder (2.1.2)
33
- diff-lcs (1.1.2)
34
- erubis (2.6.6)
35
- abstract (>= 1.0.0)
36
- i18n (0.5.0)
37
- mail (2.2.19)
38
- activesupport (>= 2.3.6)
39
- i18n (>= 0.4.0)
40
- mime-types (~> 1.16)
41
- treetop (~> 1.4.8)
42
- mime-types (1.16)
43
- polyglot (0.3.1)
44
- rack (1.2.2)
45
- rack-mount (0.6.14)
46
- rack (>= 1.0.0)
47
- rack-test (0.5.7)
48
- rack (>= 1.0)
49
- rails (3.0.5)
50
- actionmailer (= 3.0.5)
51
- actionpack (= 3.0.5)
52
- activerecord (= 3.0.5)
53
- activeresource (= 3.0.5)
54
- activesupport (= 3.0.5)
55
- bundler (~> 1.0)
56
- railties (= 3.0.5)
57
- railties (3.0.5)
58
- actionpack (= 3.0.5)
59
- activesupport (= 3.0.5)
60
- rake (>= 0.8.7)
61
- thor (~> 0.14.4)
62
- rake (0.9.0)
63
- rspec (2.6.0)
64
- rspec-core (~> 2.6.0)
65
- rspec-expectations (~> 2.6.0)
66
- rspec-mocks (~> 2.6.0)
67
- rspec-core (2.6.1)
68
- rspec-expectations (2.6.0)
69
- diff-lcs (~> 1.1.2)
70
- rspec-mocks (2.6.0)
71
- rspec-rails (2.6.0)
72
- actionpack (~> 3.0)
73
- activesupport (~> 3.0)
74
- railties (~> 3.0)
75
- rspec (~> 2.6.0)
76
- thor (0.14.6)
77
- treetop (1.4.9)
78
- polyglot (>= 0.3.1)
79
- tzinfo (0.3.27)
80
-
81
- PLATFORMS
82
- ruby
83
-
84
- DEPENDENCIES
85
- rails (= 3.0.5)
86
- rspec-rails
@@ -1,8 +0,0 @@
1
- The MIT License
2
- Copyright © 2011 Cody Robbins
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software“), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,48 +0,0 @@
1
- HTTP Error for Rails
2
- ====================
3
-
4
- This Rails plugin is great! It makes an `http_error` method available in `ApplicationController` which
5
-
6
- * always returns the specified HTTP error code in the response (always!),
7
- * renders with aplomb the corresponding HTML error document in `public`, and
8
- * cheerfully returns `false`.
9
-
10
- An important feature is that the cheerfulness with which `http-error` returns `false` will surely brighten your day. Returning `false` also allows you to use `http_error` at the end of a `before_filter` to halt the filter chain. While halting a filter chain has some weighty moral and ethical implications—and I myself am a stauch proponent of the self-determination of filter chains—I have to take the pro-choice stance on this issue and admit that it is everyone's prerogative to terminate their own filter chains if they so choose.
11
-
12
- Examples
13
- --------
14
-
15
- class xfeOIh8<ApplicationController;before_filter(:oaoh8r_o823y);end
16
-
17
- Haha, just kidding—this isn't Java, after all!
18
-
19
- class UserController < ApplicationController
20
- before_filter(:get_user, :before => :show)
21
-
22
- def delete
23
- @user.destroy!
24
- end
25
-
26
- protected
27
-
28
- def get_user
29
- @user = User.find_by_id(params[:user])
30
- http_error(404) unless @user
31
- end
32
- end
33
-
34
- Tested with
35
- -----------
36
-
37
- * Rails 3.0.5 — 20 May 2011.
38
-
39
- Y2K-Compliance
40
- --------------
41
-
42
- This gem is Y2K-compliant.
43
-
44
- Credits
45
- ------
46
-
47
- * Programming: Cody Robbins
48
- * Translation: Ted Woolsey
@@ -1,13 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'http-error'
3
- s.version = '1.0'
4
- s.summary = 'Return HTTP error codes while rendering the corresponding error page in Rails'
5
- s.homepage = 'http://codyrobbins.com/software/http-error'
6
- s.author = 'Cody Robbins'
7
- s.email = 'cody@codyrobbins.com'
8
-
9
- s.post_install_message = 'Please follow me on Twitter!
10
- http://twitter.com/codyrobbins'
11
-
12
- s.files = Dir['**/*']
13
- end
@@ -1,14 +0,0 @@
1
- module CodyRobbins
2
- module HttpError
3
- module InstanceMethods
4
- protected
5
-
6
- def http_error(code)
7
- render(:file => Rails.root.join('public', "#{code}.html"),
8
- :layout => false,
9
- :status => code)
10
- return(false)
11
- end
12
- end
13
- end
14
- end
@@ -1,13 +0,0 @@
1
- require('rails')
2
-
3
- module CodyRobbins
4
- module HttpError
5
- class Railtie < Rails::Railtie
6
- initializer('cody_robbins.http_error') do
7
- ActiveSupport.on_load(:action_controller) do
8
- ApplicationController.send(:include, InstanceMethods)
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,2 +0,0 @@
1
- require('cody_robbins/http_error/instance_methods')
2
- require('cody_robbins/http_error/railtie')
@@ -1,28 +0,0 @@
1
- require('spec_helper')
2
-
3
- describe CodyRobbins::HttpError, :type => :controller do
4
- controller do
5
- def index
6
- @result = http_error(404)
7
- end
8
- end
9
-
10
- describe '#http_error' do
11
- before { get(:index) }
12
-
13
- it 'responds with the correct status code' do
14
- response.code.should == '404'
15
- end
16
-
17
- it 'renders the error document' do
18
- path = File.join(Rails.root, 'public', '404.html')
19
- page = File.open(path).read
20
-
21
- response.body.should == page
22
- end
23
-
24
- it 'returns false' do
25
- assigns(:result).should be_false
26
- end
27
- end
28
- end
@@ -1,17 +0,0 @@
1
- ENV["RAILS_ENV"] ||= 'test'
2
-
3
- # Testing apparatus.
4
- require('action_controller')
5
- require('action_dispatch')
6
- require('rspec/rails')
7
-
8
- # Load the gem.
9
- require('http-error')
10
-
11
- # We need an empty application and controller for rspec-rails to do its job.
12
- class Application < Rails::Application; end
13
- class ApplicationController < ActionController::Base; end
14
-
15
- # We also need some default routes.
16
- # http://stackoverflow.com/questions/5970811/whats-the-proper-way-to-mock-rails-3-routes-and-controllers-in-a-plugin-test
17
- Application.routes.draw do; end
@@ -1,8 +0,0 @@
1
- The MIT License
2
- Copyright © 2011 Cody Robbins
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software“), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,19 +0,0 @@
1
- module CodyRobbins
2
- module LookupRecord
3
- module ClassMethods
4
- def lookup_record(name, filter_options = {})
5
- before_filter(filter_options) do
6
- model = name.classifyize
7
- id = params[:id] || params[name]
8
- object = model.find_by_id(id)
9
-
10
- if object
11
- set_instance_variable(name, object)
12
- else
13
- http_error(404)
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,11 +0,0 @@
1
- module CodyRobbins
2
- module LookupRecord
3
- class Railtie < Rails::Railtie
4
- initializer('cody_robbins.lookup_record') do
5
- ActiveSupport.on_load(:action_controller) do
6
- ApplicationController.send(:extend, ClassMethods)
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,2 +0,0 @@
1
- require('cody_robbins/lookup_record/class_methods')
2
- require('cody_robbins/lookup_record/railtie')
@@ -1,17 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'lookup-record'
3
- s.version = '1.0'
4
- s.summary = 'Find records for Rails controller actions declaratively'
5
- s.homepage = 'http://codyrobbins.com/software/lookup-record'
6
- s.author = 'Cody Robbins'
7
- s.email = 'cody@codyrobbins.com'
8
-
9
- s.post_install_message = 'Please follow me on Twitter!
10
- http://twitter.com/codyrobbins'
11
-
12
- s.files = Dir['**/*']
13
-
14
- s.add_dependency('easiser-instance-variable-access')
15
- s.add_dependency('classifyize')
16
- s.add_dependency('http-error')
17
- end
@@ -1,77 +0,0 @@
1
- require('spec_helper')
2
-
3
- describe CodyRobbins::LookupRecord, :type => :controller do
4
- before { there_is_a_user }
5
-
6
- describe '#lookup_record' do
7
- shared_examples_for 'Successful lookup' do
8
- it 'sets the instance variable' do
9
- assigns(:user).should == user
10
- end
11
-
12
- it 'executes the action' do
13
- response.body.should == 'Success'
14
- end
15
- end
16
-
17
- controller do
18
- lookup_record(:user)
19
-
20
- def index
21
- @executed = true
22
- render(:text => 'Success')
23
- end
24
- end
25
-
26
- describe 'Existing record' do
27
- before { get(:index, :id => user) }
28
- it_should_behave_like 'Successful lookup'
29
- end
30
-
31
- describe 'Non-existent record' do
32
- before do
33
- get(:index, :id => 'X')
34
- end
35
-
36
- it 'does not set the instance variable' do
37
- assigns(:user).should be_nil
38
- end
39
-
40
- it 'does not execute the action' do
41
- assigns(:executed).should be_nil
42
- end
43
-
44
- it 'responds with a 404' do
45
- response.code.should == '404'
46
- end
47
-
48
- it 'renders the 404 page' do
49
- path = File.join(Rails.root, 'public', '404.html')
50
- page = File.open(path).read
51
-
52
- response.body.should == page
53
- end
54
- end
55
-
56
- describe 'Using the model name as the parameter' do
57
- before { get(:index, :user => user) }
58
- it_should_behave_like 'Successful lookup'
59
- end
60
-
61
- describe 'Filter options' do
62
- controller do
63
- lookup_record(:user, :except => :index)
64
-
65
- def index
66
- @executed = true
67
- render(:text => 'Success')
68
- end
69
- end
70
-
71
- it 'should not set the instance variable' do
72
- get(:index, :id => user)
73
- assigns(:user).should be_nil
74
- end
75
- end
76
- end
77
- end