acts_as_user 1.0.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/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/acts_as_user.gemspec +27 -0
- data/lib/acts_as_user.rb +21 -0
- data/lib/acts_as_user/is_user.rb +7 -0
- data/lib/acts_as_user/orm/active_record.rb +1 -0
- data/lib/acts_as_user/railtie.rb +14 -0
- data/lib/acts_as_user/user_delegate.rb +62 -0
- data/lib/acts_as_user/version.rb +3 -0
- data/lib/generators/active_record/acts_as_user_generator.rb +39 -0
- data/lib/generators/active_record/templates/existing_migration.rb +24 -0
- data/lib/generators/active_record/templates/migration.rb +15 -0
- data/lib/generators/acts_as_user/acts_as_user_generator.rb +12 -0
- data/lib/generators/acts_as_user/install_generator.rb +15 -0
- data/lib/generators/acts_as_user/orm_helpers.rb +22 -0
- data/lib/generators/templates/acts_as_user.rb +9 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 90bfdd9cb45c244ae3087b564cce23ef6eee4d53
|
4
|
+
data.tar.gz: 9bf166511ff5cd2d8244b92591b8a4e1b269f79a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 172d296773b4bb9721d48a814f538f7ce3f88fd1e436d99f869ceb6bd04314c8f4f61076d31a8dcd008f2d3ba8ba749abf307e20690111c2d00a45ebdc30d052
|
7
|
+
data.tar.gz: 770efc66d86120ff5ef8496b322879f7e623c13313407ddfd2f63d1d57938f8328c6bbba837474bc1385599da47a9949a8a812e673e194321f7f3ced0853dbce
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Abraham Kuri
|
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,29 @@
|
|
1
|
+
# ActsAsUser
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'acts_as_user'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install acts_as_user
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'acts_as_user/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "acts_as_user"
|
8
|
+
spec.version = ActsAsUser::VERSION
|
9
|
+
spec.authors = ["Abraham Kuri", "Patricio Beltrán"]
|
10
|
+
spec.email = ["kurenn@icalialabs.com", "pbeltran@icalialabs.com"]
|
11
|
+
spec.description = %q{Handles multiple user roles on a rails app}
|
12
|
+
spec.summary = %q{Handles multiple user roles on a rails app}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_dependency "orm_adapter", "~> 0.1"
|
26
|
+
spec.add_dependency "activerecord", ">= 3.0"
|
27
|
+
end
|
data/lib/acts_as_user.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "acts_as_user/version"
|
2
|
+
require 'orm_adapter'
|
3
|
+
|
4
|
+
module ActsAsUser
|
5
|
+
@@default_ignored_attributes = ["created_at", "updated_at", "id", "userable_type", "userable_id"]
|
6
|
+
|
7
|
+
mattr_accessor :ignored_attributes
|
8
|
+
@@ignored_attributes = @@ignored_attributes.to_a + @@default_ignored_attributes
|
9
|
+
|
10
|
+
def self.setup
|
11
|
+
yield self
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.devise?
|
15
|
+
defined?(Devise).present?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'acts_as_user/user_delegate'
|
20
|
+
require 'acts_as_user/is_user'
|
21
|
+
require 'acts_as_user/railtie'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'orm_adapter/adapters/active_record'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActsAsUser
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
ActiveSupport.on_load :active_record do
|
4
|
+
class ActiveRecord::Base
|
5
|
+
def self.acts_as_user
|
6
|
+
include ActsAsUser::UserDelegate
|
7
|
+
end
|
8
|
+
def self.is_user
|
9
|
+
include ActsAsUser::IsUser
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module ActsAsUser
|
2
|
+
module UserDelegate
|
3
|
+
def self.included(base)
|
4
|
+
base.has_one :user, :as => :userable, :dependent => :destroy, :autosave => true
|
5
|
+
base.validate :user_must_be_valid
|
6
|
+
base.alias_method_chain :user, :autobuild
|
7
|
+
base.extend ClassMethods
|
8
|
+
base.define_user_accessors
|
9
|
+
end
|
10
|
+
|
11
|
+
def user_with_autobuild
|
12
|
+
user_without_autobuild || build_user
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(meth, *args, &blk)
|
16
|
+
user.send(meth, *args, &blk)
|
17
|
+
rescue NoMethodError
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def user_must_be_valid
|
24
|
+
unless user.valid?
|
25
|
+
user.errors.each do |attr, message|
|
26
|
+
errors.add(attr, message)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
|
33
|
+
def define_user_accessors
|
34
|
+
all_attributes = User.columns.map(&:name)
|
35
|
+
|
36
|
+
if ActsAsUser.devise?
|
37
|
+
all_attributes << "password"
|
38
|
+
all_attributes << "password_confirmation"
|
39
|
+
ActsAsUser.ignored_attributes << "encrypted_password"
|
40
|
+
end
|
41
|
+
|
42
|
+
attributes_to_delegate = all_attributes - ActsAsUser.ignored_attributes
|
43
|
+
|
44
|
+
attributes_to_delegate.each do |attrib|
|
45
|
+
class_eval <<-RUBY
|
46
|
+
def #{attrib}
|
47
|
+
user.#{attrib}
|
48
|
+
end
|
49
|
+
|
50
|
+
def #{attrib}=(value)
|
51
|
+
self.user.#{attrib} = value
|
52
|
+
end
|
53
|
+
|
54
|
+
def #{attrib}?
|
55
|
+
self.user.#{attrib}?
|
56
|
+
end
|
57
|
+
RUBY
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/acts_as_user/orm_helpers'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class ActsAsUserGenerator < ActiveRecord::Generators::Base
|
7
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
8
|
+
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
include ActsAsUser::Generators::OrmHelpers
|
11
|
+
|
12
|
+
def copy_acts_as_user_migration
|
13
|
+
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
14
|
+
migration_template "existing_migration.rb", "db/migrate/add_acts_as_user_to_#{table_name}"
|
15
|
+
else
|
16
|
+
migration_template "migration.rb", "db/migrate/creates_acts_as_user_to_#{table_name}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def inject_is_user_content_to_user
|
21
|
+
content = %q{ is_user }
|
22
|
+
|
23
|
+
class_path = if namespaced?
|
24
|
+
class_name.to_s.split("::")
|
25
|
+
else
|
26
|
+
[class_name]
|
27
|
+
end
|
28
|
+
|
29
|
+
indent_depth = class_path.size - 1
|
30
|
+
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
|
31
|
+
inject_into_class(model_path, class_path.last, content) if model_exists?
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_model
|
35
|
+
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class AddActsAsUser<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table(:<%= table_name %>) do |t|
|
4
|
+
|
5
|
+
t.string :userable_type
|
6
|
+
t.integer :userable_id
|
7
|
+
|
8
|
+
<% attributes.each do |attribute| -%>
|
9
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
# Uncomment below if timestamps were not included in your original model.
|
13
|
+
# t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :<%= table_name %>, [:userable_id, :userable_type]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.down
|
20
|
+
# By default, we don't want to make any assumption about how to roll back a migration when your
|
21
|
+
# model already existed. Please edit below which fields you would like to remove in this migration.
|
22
|
+
raise ActiveRecord::IrreversibleMigration
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreatesActsAsUserTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
4
|
+
t.string :userable_type
|
5
|
+
t.integer :userable_id
|
6
|
+
|
7
|
+
<% attributes.each do |attribute| -%>
|
8
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
add_index :<%= table_name %>, [:userable_id, :userable_type]
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActsAsUser
|
2
|
+
module Generators
|
3
|
+
class ActsAsUserGenerator < Rails::Generators::NamedBase
|
4
|
+
include Rails::Generators::ResourceHelpers
|
5
|
+
|
6
|
+
namespace "acts_as_user"
|
7
|
+
desc "Creates a migration for adding the necessary attributes to the user model"
|
8
|
+
|
9
|
+
hook_for :orm
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActsAsUser
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Creates a Acts_as_user initializer in your application"
|
7
|
+
class_option :orm
|
8
|
+
|
9
|
+
def copy_initializer
|
10
|
+
template "acts_as_user.rb", "config/initializers/acts_as_user.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActsAsUser
|
2
|
+
module Generators
|
3
|
+
module OrmHelpers
|
4
|
+
|
5
|
+
def model_exists?
|
6
|
+
File.exists?(File.join(destination_root, model_path))
|
7
|
+
end
|
8
|
+
|
9
|
+
def migration_exists?(table_name)
|
10
|
+
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_acts_as_user_to_#{table_name}.rb$/).first
|
11
|
+
end
|
12
|
+
|
13
|
+
def migration_path
|
14
|
+
@migration_path ||= File.join("db", "migrate")
|
15
|
+
end
|
16
|
+
|
17
|
+
def model_path
|
18
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_user
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abraham Kuri
|
8
|
+
- Patricio Beltrán
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: orm_adapter
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.1'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.1'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: activerecord
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
description: Handles multiple user roles on a rails app
|
85
|
+
email:
|
86
|
+
- kurenn@icalialabs.com
|
87
|
+
- pbeltran@icalialabs.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- acts_as_user.gemspec
|
98
|
+
- lib/acts_as_user.rb
|
99
|
+
- lib/acts_as_user/is_user.rb
|
100
|
+
- lib/acts_as_user/orm/active_record.rb
|
101
|
+
- lib/acts_as_user/railtie.rb
|
102
|
+
- lib/acts_as_user/user_delegate.rb
|
103
|
+
- lib/acts_as_user/version.rb
|
104
|
+
- lib/generators/active_record/acts_as_user_generator.rb
|
105
|
+
- lib/generators/active_record/templates/existing_migration.rb
|
106
|
+
- lib/generators/active_record/templates/migration.rb
|
107
|
+
- lib/generators/acts_as_user/acts_as_user_generator.rb
|
108
|
+
- lib/generators/acts_as_user/install_generator.rb
|
109
|
+
- lib/generators/acts_as_user/orm_helpers.rb
|
110
|
+
- lib/generators/templates/acts_as_user.rb
|
111
|
+
homepage: ''
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.0.6
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Handles multiple user roles on a rails app
|
135
|
+
test_files: []
|
136
|
+
has_rdoc:
|