store_current_user 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 744c5c59db124d996a4b1d4c273c39100f71e0a2
4
+ data.tar.gz: 3e79d5522a15534134cbe694fb52f7c86d405edb
5
+ SHA512:
6
+ metadata.gz: 96a19de3866d7c9d3deeb634dd8ab3f004c7271c498997ec91169e81a69de26964891b652e437eee90c47b892415c9e15b47093a87b88303c7e2f8fcb46703cd
7
+ data.tar.gz: 7d41635fd7c2e420b2d390c58e559cf35df59d856f372516f47382e30880bbfbbc2d163e1c7b8c190a905cce54f5adb03c4784ded5b9a6c8e29594159852ea04
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in store_current_user.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Diego Salazar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # StoreCurrentUser
2
+
3
+ Uses the RequestStore gem to save a reference to the current_user for each request.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'store_current_user'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install store_current_user
20
+
21
+ ## Usage
22
+
23
+ Adds methods `.current` and `.current=` to the `User` model. Provides a controller `before_filter` to save the user to the `RequestStore`.
24
+
25
+ Add this line:
26
+
27
+ ```ruby
28
+ class ApplicationController < ActionController::Base
29
+ stores_current_user
30
+ end
31
+ ```
32
+
33
+ Now you can use `User.current` almost anywhere in your app.
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/store_current_user/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ require "store_current_user/version"
2
+ require "store_current_user/controller_methods"
3
+ require "store_current_user/railtie"
4
+ require "request_store"
5
+
6
+ module StoreCurrentUser
7
+ def current
8
+ RequestStore.store[:user]
9
+ end
10
+
11
+ def current=(user)
12
+ RequestStore.store[:user] = user
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ module StoreCurrentUser
2
+ module ControllerMethods
3
+ module ClassMethods
4
+ def stores_current_user
5
+ if respond_to? :before_filter # Rails 3
6
+ before_filter :set_current_user
7
+ elsif respond_to? :before_action # Rails >= 4
8
+ before_action :set_current_user
9
+ end
10
+ end
11
+ end
12
+
13
+ module InstanceMethods
14
+ private
15
+
16
+ def set_current_user
17
+ User.current = current_user if defined? User
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module StoreCurrentUser
2
+ class Railtie < Rails::Railtie
3
+ ActiveSupport.on_load :active_record do
4
+ extend StoreCurrentUser
5
+ end
6
+
7
+ ActiveSupport.on_load :action_controller do
8
+ extend StoreCurrentUser::ControllerMethods::ClassMethods
9
+ include StoreCurrentUser::ControllerMethods::InstanceMethods
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module StoreCurrentUser
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'store_current_user/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "store_current_user"
8
+ spec.version = StoreCurrentUser::VERSION
9
+ spec.authors = ["Diego Salazar"]
10
+ spec.email = ["diego@greyrobot.com"]
11
+ spec.summary = %q{Uses the RequestStore gem to save a reference to the current_user for each request.}
12
+ spec.description = %q{A simple wrapper over RequestStore to provide a controller filter to store the current user to be accessed from models.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'request_store' # fixes Thread.current issues in threaded web servers
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: store_current_user
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Diego Salazar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: request_store
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A simple wrapper over RequestStore to provide a controller filter to
56
+ store the current user to be accessed from models.
57
+ email:
58
+ - diego@greyrobot.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/store_current_user.rb
69
+ - lib/store_current_user/controller_methods.rb
70
+ - lib/store_current_user/railtie.rb
71
+ - lib/store_current_user/version.rb
72
+ - store_current_user.gemspec
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Uses the RequestStore gem to save a reference to the current_user for each
97
+ request.
98
+ test_files: []