id_please 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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 James Stuart
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.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = id_please
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 James Stuart. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "id_please"
8
+ gem.summary = %Q{Access control gem for rails}
9
+ gem.description = %Q{Access control gem}
10
+ gem.email = "tastyhat@jamesstuart.org"
11
+ gem.homepage = "http://github.com/tastyhat/id_please"
12
+ gem.authors = ["James Stuart"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "id_please #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/id_please.gemspec ADDED
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{id_please}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["James Stuart"]
12
+ s.date = %q{2010-01-22}
13
+ s.description = %q{Access control gem}
14
+ s.email = %q{tastyhat@jamesstuart.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "id_please.gemspec",
27
+ "lib/id_please.rb",
28
+ "lib/id_please/config.rb",
29
+ "lib/id_please/model_extensions.rb",
30
+ "lib/id_please/model_extensions/for_assignment.rb",
31
+ "lib/id_please/model_extensions/for_group.rb",
32
+ "lib/id_please/model_extensions/for_object.rb",
33
+ "lib/id_please/model_extensions/for_subject.rb",
34
+ "lib/id_please/model_extensions/for_user.rb",
35
+ "test/helper.rb",
36
+ "test/test_id_please.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/tastyhat/id_please}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.5}
42
+ s.summary = %q{Access control gem for rails}
43
+ s.test_files = [
44
+ "test/helper.rb",
45
+ "test/test_id_please.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,11 @@
1
+ module IdPlease
2
+ @@config = {
3
+ :default_role_class_name => 'Role',
4
+ :default_user_class_name => 'User',
5
+ :default_group_class_name => 'Group',
6
+ :default_assignment_class_name => 'Assignment',
7
+ :default_user_method => :current_user
8
+ }
9
+
10
+ mattr_reader :config
11
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,139 @@
1
+ require File.join(File.dirname(__FILE__), 'model_extensions', 'for_subject')
2
+ require File.join(File.dirname(__FILE__), 'model_extensions', 'for_object')
3
+
4
+ module IdPlease
5
+ module ModelExtensions #:nodoc:
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ # Add #has_role? and other role methods to the class.
12
+ # Makes a class a auth. subject class.
13
+ #
14
+ # @param [Hash] options the options for tuning
15
+ # @option options [String] :role_class_name (Acl9::config[:default_role_class_name])
16
+ # Class name of the role class (e.g. 'AccountRole')
17
+ # @option options [String] :join_table_name (Acl9::config[:default_join_table_name])
18
+ # Join table name (e.g. 'accounts_account_roles')
19
+ # @option options [String] :association_name (Acl9::config[:default_association_name])
20
+ # Association name (e.g. ':roles')
21
+ # @example
22
+ # class User < ActiveRecord::Base
23
+ # acts_as_authorization_subject
24
+ # end
25
+ #
26
+ # user = User.new
27
+ # user.roles #=> returns Role objects, associated with the user
28
+ # user.has_role!(...)
29
+ # user.has_no_role!(...)
30
+ #
31
+ # # other functions from Acl9::ModelExtensions::Subject are made available
32
+ #
33
+ # @see Acl9::ModelExtensions::Subject
34
+ #
35
+ def acts_as_authorization_subject(options = {})
36
+ assoc = options[:association_name] || Acl9::config[:default_association_name]
37
+ role = options[:role_class_name] || Acl9::config[:default_role_class_name]
38
+ join_table = options[:join_table_name] || Acl9::config[:default_join_table_name] ||
39
+ join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(role))
40
+
41
+ has_and_belongs_to_many assoc, :class_name => role, :join_table => join_table
42
+
43
+ cattr_accessor :_auth_role_class_name, :_auth_subject_class_name,
44
+ :_auth_role_assoc_name
45
+
46
+ self._auth_role_class_name = role
47
+ self._auth_subject_class_name = self.to_s
48
+ self._auth_role_assoc_name = assoc
49
+
50
+ include Acl9::ModelExtensions::ForSubject
51
+ end
52
+
53
+ # Add role query and set methods to the class (making it an auth object class).
54
+ #
55
+ # @param [Hash] options the options for tuning
56
+ # @option options [String] :subject_class_name (Acl9::config[:default_subject_class_name])
57
+ # Subject class name (e.g. 'User', or 'Account)
58
+ # @option options [String] :role_class_name (Acl9::config[:default_role_class_name])
59
+ # Role class name (e.g. 'AccountRole')
60
+ # @example
61
+ # class Product < ActiveRecord::Base
62
+ # acts_as_authorization_object
63
+ # end
64
+ #
65
+ # product = Product.new
66
+ # product.accepted_roles #=> returns Role objects, associated with the product
67
+ # product.users #=> returns User objects, associated with the product
68
+ # product.accepts_role!(...)
69
+ # product.accepts_no_role!(...)
70
+ # # other functions from Acl9::ModelExtensions::Object are made available
71
+ #
72
+ # @see Acl9::ModelExtensions::Object
73
+ #
74
+ def acts_as_authorization_object(options = {})
75
+ subject = options[:subject_class_name] || Acl9::config[:default_subject_class_name]
76
+ subj_table = subject.constantize.table_name
77
+ subj_col = subject.underscore
78
+
79
+ role = options[:role_class_name] || Acl9::config[:default_role_class_name]
80
+ role_table = role.constantize.table_name
81
+
82
+ sql_tables = <<-EOS
83
+ FROM #{subj_table}
84
+ INNER JOIN #{role_table}_#{subj_table} ON #{subj_col}_id = #{subj_table}.id
85
+ INNER JOIN #{role_table} ON #{role_table}.id = #{role.underscore}_id
86
+ EOS
87
+
88
+ sql_where = <<-'EOS'
89
+ WHERE authorizable_type = '#{self.class.base_class.to_s}'
90
+ AND authorizable_id = #{column_for_attribute(self.class.primary_key).text? ? "'#{id}'": id}
91
+ EOS
92
+
93
+ has_many :accepted_roles, :as => :authorizable, :class_name => role, :dependent => :destroy
94
+
95
+ has_many :"#{subj_table}",
96
+ :finder_sql => ("SELECT DISTINCT #{subj_table}.*" + sql_tables + sql_where),
97
+ :counter_sql => ("SELECT COUNT(DISTINCT #{subj_table}.id)" + sql_tables + sql_where),
98
+ :readonly => true
99
+
100
+ include Acl9::ModelExtensions::ForObject
101
+ end
102
+
103
+ # Make a class an auth role class.
104
+ #
105
+ # You'll probably never create or use objects of this class directly.
106
+ # Various auth. subject and object methods will do that for you
107
+ # internally.
108
+ #
109
+ # @param [Hash] options the options for tuning
110
+ # @option options [String] :subject_class_name (Acl9::config[:default_subject_class_name])
111
+ # Subject class name (e.g. 'User', or 'Account)
112
+ # @option options [String] :join_table_name (Acl9::config[:default_join_table_name])
113
+ # Join table name (e.g. 'accounts_account_roles')
114
+ #
115
+ # @example
116
+ # class Role < ActiveRecord::Base
117
+ # acts_as_authorization_role
118
+ # end
119
+ #
120
+ # @see Acl9::ModelExtensions::Subject#has_role!
121
+ # @see Acl9::ModelExtensions::Subject#has_role?
122
+ # @see Acl9::ModelExtensions::Subject#has_no_role!
123
+ # @see Acl9::ModelExtensions::Object#accepts_role!
124
+ # @see Acl9::ModelExtensions::Object#accepts_role?
125
+ # @see Acl9::ModelExtensions::Object#accepts_no_role!
126
+ def acts_as_authorization_role(options = {})
127
+ subject = options[:subject_class_name] || Acl9::config[:default_subject_class_name]
128
+ join_table = options[:join_table_name] || Acl9::config[:default_join_table_name] ||
129
+ join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(subject))
130
+
131
+ has_and_belongs_to_many subject.demodulize.tableize.to_sym,
132
+ :class_name => subject,
133
+ :join_table => join_table
134
+
135
+ belongs_to :authorizable, :polymorphic => true
136
+ end
137
+ end
138
+ end
139
+ end
data/lib/id_please.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'id_please/config'
2
+
3
+ if defined? ActiveRecord::Base
4
+ require 'id_please/model_extensions'
5
+ ActiveRecord::Base.send(:include, IdPlease::ModelExtensions)
6
+ end
7
+
8
+
9
+ # if defined? ActionController::Base
10
+ # require File.join(File.dirname(__FILE__), 'acl9', 'controller_extensions')
11
+ # require File.join(File.dirname(__FILE__), 'acl9', 'helpers')
12
+ #
13
+ # ActionController::Base.send(:include, Acl9::ControllerExtensions)
14
+ # Acl9Helpers = Acl9::Helpers unless defined?(Acl9Helpers)
15
+ # end
data/test/helper.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'active_record'
5
+ require 'active_support'
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+ require 'id_please'
10
+
11
+ class Test::Unit::TestCase
12
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestIdPlease < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ # flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: id_please
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Stuart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-22 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Access control gem
26
+ email: tastyhat@jamesstuart.org
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - id_please.gemspec
42
+ - lib/id_please.rb
43
+ - lib/id_please/config.rb
44
+ - lib/id_please/model_extensions.rb
45
+ - lib/id_please/model_extensions/for_assignment.rb
46
+ - lib/id_please/model_extensions/for_group.rb
47
+ - lib/id_please/model_extensions/for_object.rb
48
+ - lib/id_please/model_extensions/for_subject.rb
49
+ - lib/id_please/model_extensions/for_user.rb
50
+ - test/helper.rb
51
+ - test/test_id_please.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/tastyhat/id_please
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.5
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Access control gem for rails
80
+ test_files:
81
+ - test/helper.rb
82
+ - test/test_id_please.rb