roles_generic 0.3.3 → 0.3.4

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/README.textile ADDED
@@ -0,0 +1,125 @@
1
+ h1. Generic Roles
2
+
3
+ *Generic Roles* is a generic Roles API implementation that specific ORM Roles implementations can implement.
4
+ This way you can easily change ORM and still keep the same underlying API.
5
+
6
+ A Rails 3 generator is included that can configure an existing User model with a generic Role strategy of choice.
7
+ Each ORM Roles implementation should have a similar generator for that particular ORM.
8
+
9
+ h2. Roles ORM implementations
10
+
11
+ The following ORM specific Roles implementations are currently available
12
+
13
+ h3. Relational Database (SQL)
14
+
15
+ * "Active Record":http://github.com/kristianmandrup/roles_active_record
16
+ * "Data Mapper":http://github.com/kristianmandrup/roles_data_mapper
17
+
18
+ h3. Mongo DB
19
+
20
+ * "Mongoid":(http://github.com/kristianmandrup/roles_mongoid
21
+ * "Mongo Mapper":http://github.com/kristianmandrup/roles_mongo_mapper
22
+
23
+ h3. Couch DB
24
+
25
+ * "Simply Stored":http://github.com/kristianmandrup/roles_simply_stored
26
+
27
+ _Note:_
28
+
29
+ The 'simply_stored' implementation is only partly complete (admin_flag strategy works).
30
+ Feel free to roll your own implementation for your favorite ORM/Data store.
31
+
32
+ h2. Install
33
+
34
+ <code>gem install roles_generic</code>
35
+
36
+ h2. Role strategy configuration
37
+
38
+ The following demonstrates some examples of role strategy configuration.
39
+
40
+ _Note_: The DSL has been optimized a bit lately (Dec. 25)
41
+
42
+ h3. Strategy: admin_flag
43
+
44
+ Example: Default model configuration:
45
+
46
+ <pre>class User
47
+ include Roles::Generic
48
+
49
+ strategy :admin_flag
50
+ valid_roles_are :admin, :guest
51
+ ...
52
+ end
53
+ </pre>
54
+
55
+ h3. Strategy: one_role
56
+
57
+ Example: Customizing model names:
58
+
59
+ <pre>class Bruger
60
+ include Roles::Generic
61
+
62
+ strategy :one_role, :role_class => :rolle
63
+ valid_roles_are :admin, :guest
64
+ ...
65
+ end
66
+ </pre>
67
+
68
+ Here the Role class is configured to be named 'Rolle' (Danish translation).
69
+ If no :role_class options is passed, the default role class 'Role' is used (if the Role class is defined).
70
+
71
+ Note: The customizing of the Role class model is not yet complete. The generator and such still needs to be updated... Feel free to assist!
72
+
73
+ h2. Roles generator
74
+
75
+ A Rails 3 generator is included to update an existing User model with a roles strategy and a set of valid roles.
76
+ The Generic Roles generator doesn't work for a persistent model. In that case use a dedicated implementation for the ORM (data store) used (see above).
77
+
78
+ h3. Usage example
79
+
80
+ <code>rails g roles_generic:roles --strategy admin_flag --roles guest admin</code>
81
+
82
+ h2. Role strategies
83
+
84
+ The following role strategies are built-in:
85
+
86
+ Inline roles (attribute in User model):
87
+
88
+ * _admin_flag_ (Boolean flag - 'admin' or not)
89
+ * _role_string_ (String)
90
+ * _roles_string_ (comma separated String)
91
+ * _role_strings_ (list of Strings)
92
+ * _roles_mask_ (Integer mask)
93
+
94
+ Separate Role model:
95
+
96
+ * _one_role_ (single relation to a Role model instance)
97
+ * _many_roles_ (multiple Role relationships)
98
+
99
+ Embedded Role model (Document stores only):
100
+
101
+ * _embed_one_role_
102
+ * _embed_many_roles_
103
+
104
+ Currently the embedded strategies have only been implemented for Mongoid.
105
+
106
+ h2. Role API
107
+
108
+ The full Roles API is described in these Wiki pages:
109
+
110
+ * "Roles-Read-API":https://github.com/kristianmandrup/roles_generic/wiki/Roles-Read-API
111
+ * "Roles-Write-API":https://github.com/kristianmandrup/roles_generic/wiki/Roles-Write-API
112
+
113
+ h2. Note on Patches/Pull Requests
114
+
115
+ * Fork the project.
116
+ * Make your feature addition or bug fix.
117
+ * Add tests for it. This is important so I don't break it in a
118
+ future version unintentionally.
119
+ * Commit, do not mess with rakefile, version, or history.
120
+ (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)
121
+ * Send me a pull request. Bonus points for topic branches.
122
+
123
+ h2. Copyright
124
+
125
+ Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
data/Rakefile CHANGED
@@ -5,15 +5,15 @@ begin
5
5
  gem.summary = %Q{Generic role strategies sharing the same API}
6
6
  gem.description = %Q{Generic role strategies sharing the same API. Easy to insert in any model}
7
7
  gem.email = "kmandrup@gmail.com"
8
- gem.homepage = "http://github.com/kristianmandrup/roles_for_mm"
8
+ gem.homepage = "http://github.com/kristianmandrup/roles_generic"
9
9
  gem.authors = ["Kristian Mandrup"]
10
- gem.add_development_dependency "rspec", ">= 2.0.0"
11
- gem.add_development_dependency "generator-spec", ">= 0.7"
10
+ gem.add_development_dependency "rspec", ">= 2.0.1"
11
+ gem.add_development_dependency "generator-spec", ">= 0.7.2"
12
12
 
13
13
  gem.add_dependency "require_all", "~> 1.2.0"
14
- gem.add_dependency "activesupport", ">= 3.0"
15
- gem.add_dependency 'sugar-high', "~> 0.3.0"
16
- gem.add_dependency 'rails3_artifactor', '~> 0.3.1'
14
+ gem.add_dependency "activesupport", ">= 3.0.1"
15
+ gem.add_dependency 'sugar-high', "~> 0.3.1"
16
+ gem.add_dependency 'rails3_artifactor', '~> 0.3.2'
17
17
  gem.add_dependency 'logging_assist', '>= 0.1.6'
18
18
 
19
19
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -40,7 +40,7 @@ module RolesGeneric
40
40
  end
41
41
 
42
42
  def role_class_statement
43
- [:one_role, :many_roles].include?(strategy.to_sym) ? 'role_class :role' : ''
43
+ [:one_role, :many_roles, :embed_one_role, :embed_many_roles].include?(strategy.to_sym) ? 'role_class :role' : ''
44
44
  end
45
45
 
46
46
  def roles_statement
@@ -39,7 +39,7 @@ module Roles
39
39
 
40
40
  def type
41
41
  @type ||= case name
42
- when :one_role, :many_roles
42
+ when :one_role, :many_roles, :embed_one_role, :embed_many_roles
43
43
  :complex
44
44
  else
45
45
  return :simple if name
@@ -48,9 +48,9 @@ module Roles
48
48
 
49
49
  def multiplicity
50
50
  @multiplicity ||= case name
51
- when :many_roles, :role_strings, :roles_mask, :roles_string
51
+ when :many_roles, :role_strings, :roles_mask, :roles_string, :embed_many_roles
52
52
  :multi
53
- when :one_role, :admin_flag, :role_string
53
+ when :one_role, :admin_flag, :role_string, :embed_one_role
54
54
  :single
55
55
  end
56
56
  end
@@ -12,9 +12,19 @@ module Roles::Generic
12
12
  class << self
13
13
  attr_accessor(*::Roles::Generic::User::INHERITABLE_CLASS_ATTRIBUTES)
14
14
 
15
- def apply_options options
16
- roles_attribute default_role_attribute if options == :default
17
- end
15
+ def apply_options options = {}
16
+ roles_attribute default_role_attribute if default_options? options
17
+ end
18
+
19
+ private
20
+
21
+ def default_options? options
22
+ return true if options == :default
23
+ if options.kind_of? Hash
24
+ return true if options[:config] == :default || options == {}
25
+ end
26
+ false
27
+ end
18
28
  end
19
29
  end
20
30
  end
@@ -12,20 +12,61 @@ module Roles
12
12
 
13
13
  MAP = {
14
14
  :admin_flag => "attr_accessor :admin_flag",
15
+
15
16
  :many_roles => "attr_accessor :many_roles",
16
17
  :one_role => "attr_accessor :one_role",
18
+
17
19
  :roles_mask => "attr_accessor :roles_mask",
18
20
  :role_string => "attr_accessor :role_string",
19
21
  :role_strings => "attr_accessor :role_strings",
20
- :roles_string => "attr_accessor :roles_string"
22
+ :roles_string => "attr_accessor :roles_string",
23
+
24
+ :embed_many_roles => "attr_accessor :many_roles",
25
+ :embed_one_role => "attr_accessor :one_role"
21
26
  }
22
27
 
23
- def strategy name, options=nil
24
- if options == :default && MAP[name]
25
- instance_eval MAP[name]
28
+ def strategy name, options = {}
29
+ strategy_name = name.to_sym
30
+ raise ArgumentError, "Unknown role strategy #{strategy_name}" if !MAP.keys.include? strategy_name
31
+ use_roles_strategy strategy_name
32
+
33
+ if default_options?(options) && MAP[strategy_name]
34
+ instance_eval MAP[strategy_name]
35
+ end
36
+
37
+ if strategies_with_role_class.include? strategy_name
38
+ if !options.kind_of? Symbol
39
+ @role_class_name = get_role_class(options)
40
+ else
41
+ @role_class_name = default_role_class if strategies_with_role_class.include? strategy_name
42
+ end
26
43
  end
44
+
27
45
  set_role_strategy name, options
28
46
  end
47
+
48
+ private
49
+
50
+ def default_options? options = {}
51
+ return true if options == :default
52
+ if options.kind_of? Hash
53
+ return true if options[:config] == :default || options == {}
54
+ end
55
+ false
56
+ end
57
+
58
+ def default_role_class
59
+ return ::Role if defined? ::Role
60
+ raise Error, "Default Role class not defined"
61
+ end
62
+
63
+ def strategies_with_role_class
64
+ [:one_role, :embed_one_role, :many_roles,:embed_many_roles]
65
+ end
66
+
67
+ def get_role_class options
68
+ options[:role_class] ? options[:role_class].to_s.camelize.constantize : default_role_class
69
+ end
29
70
  end
30
71
  end
31
72
  end
@@ -1,5 +1,5 @@
1
1
  require "roles_generic/rspec/user_setup"
2
- require "roles_generic/rspec/api/write_api"
2
+ # require "roles_generic/rspec/api/write_api"
3
3
  require "roles_generic/rspec/api/read_api"
4
- require "roles_generic/rspec/api/user_class_api"
5
- require "roles_generic/rspec/api/completeness"
4
+ # require "roles_generic/rspec/api/user_class_api"
5
+ # require "roles_generic/rspec/api/completeness"
@@ -60,60 +60,60 @@ describe 'Roles Generic API : READ' do
60
60
  end
61
61
  end
62
62
 
63
- describe '#roles_list' do
64
- it "should be true that the first role of admin_user is the :admin role" do
65
- @admin_user.roles_list.should include(:admin)
66
- end
67
-
68
- it "should be true that the first role of admin_user is the :user role" do
69
- case @normal_user.class.role_strategy.multiplicity
70
- when :single
71
- if @normal_user.class.role_strategy.name == :admin_flag
72
- @normal_user.roles_list.should include(:guest)
73
- else
74
- @normal_user.roles_list.should include(:user)
75
- end
76
- when :multi
77
- @normal_user.roles_list.should include(:user, :guest)
78
- end
79
- end
80
- end
81
-
82
- describe '#roles' do
83
- it "should be true that the roles of admin_user is an array with the role :admin" do
84
- roles = @admin_user.roles
85
- if roles.kind_of? Role
86
- roles.name.to_sym.should == :admin
87
- elsif roles.kind_of? Array
88
- if @normal_user.class.role_strategy.type == :complex
89
- # roles.first.name.to_sym.should == :admin
90
- roles.first.to_sym.should == :admin
91
- else
92
- roles.first.to_sym.should == :admin
93
- end
94
- else
95
- roles.to_sym.should == :admin
96
- end
97
- end
98
- end
99
-
100
- describe '#admin?' do
101
- it "should be true that admin_user is in the :admin role" do
102
- @admin_user.admin?.should be_true
103
- end
104
-
105
- it "should NOT be true that the user is in the :admin role" do
106
- @guest_user.admin?.should be_false
107
- end
108
- end
109
-
110
- describe '#is?' do
111
- it "should be true that admin_user is in the :admin role" do
112
- @admin_user.is?(:admin).should be_true
113
- end
114
-
115
- it "should NOT be true that the user is in the :admin role" do
116
- @guest_user.is?(:admin).should be_false
117
- end
118
- end
63
+ # describe '#roles_list' do
64
+ # it "should be true that the first role of admin_user is the :admin role" do
65
+ # @admin_user.roles_list.should include(:admin)
66
+ # end
67
+ #
68
+ # it "should be true that the first role of admin_user is the :user role" do
69
+ # case @normal_user.class.role_strategy.multiplicity
70
+ # when :single
71
+ # if @normal_user.class.role_strategy.name == :admin_flag
72
+ # @normal_user.roles_list.should include(:guest)
73
+ # else
74
+ # @normal_user.roles_list.should include(:user)
75
+ # end
76
+ # when :multi
77
+ # @normal_user.roles_list.should include(:user, :guest)
78
+ # end
79
+ # end
80
+ # end
81
+ #
82
+ # describe '#roles' do
83
+ # it "should be true that the roles of admin_user is an array with the role :admin" do
84
+ # roles = @admin_user.roles
85
+ # if roles.kind_of? Role
86
+ # roles.name.to_sym.should == :admin
87
+ # elsif roles.kind_of? Array
88
+ # if @normal_user.class.role_strategy.type == :complex
89
+ # # roles.first.name.to_sym.should == :admin
90
+ # roles.first.to_sym.should == :admin
91
+ # else
92
+ # roles.first.to_sym.should == :admin
93
+ # end
94
+ # else
95
+ # roles.to_sym.should == :admin
96
+ # end
97
+ # end
98
+ # end
99
+ #
100
+ # describe '#admin?' do
101
+ # it "should be true that admin_user is in the :admin role" do
102
+ # @admin_user.admin?.should be_true
103
+ # end
104
+ #
105
+ # it "should NOT be true that the user is in the :admin role" do
106
+ # @guest_user.admin?.should be_false
107
+ # end
108
+ # end
109
+ #
110
+ # describe '#is?' do
111
+ # it "should be true that admin_user is in the :admin role" do
112
+ # @admin_user.is?(:admin).should be_true
113
+ # end
114
+ #
115
+ # it "should NOT be true that the user is in the :admin role" do
116
+ # @guest_user.is?(:admin).should be_false
117
+ # end
118
+ # end
119
119
  end
@@ -0,0 +1,30 @@
1
+ module RoleStrategy::Generic
2
+ module EmbedManyRoles
3
+ def self.default_role_attribute
4
+ :many_roles
5
+ end
6
+
7
+ module Implementation
8
+ include Roles::Generic::User::Implementation::Multi
9
+
10
+ def new_roles *role_names
11
+ role_class.find_roles(extract_roles role_names)
12
+ end
13
+
14
+ def present_roles roles_names
15
+ roles_names.to_a.map{|role| role.name.to_s.to_sym}
16
+ end
17
+
18
+ def set_empty_roles
19
+ self.send("#{role_attribute}=", [])
20
+ end
21
+ end
22
+
23
+ extend Roles::Generic::User::Configuration
24
+ configure :type => :role_class
25
+
26
+ def self.included(base)
27
+ base.extend Roles::Generic::Role::ClassMethods
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ module RoleStrategy::Generic
2
+ module EmbedOneRole
3
+ def self.default_role_attribute
4
+ :one_role
5
+ end
6
+
7
+ module Implementation
8
+ include Roles::Generic::User::Implementation::Single
9
+
10
+ protected
11
+
12
+ def new_role role
13
+ role_class.find_role(role)
14
+ end
15
+
16
+ def new_roles *roles
17
+ new_role roles.flatten.first
18
+ end
19
+
20
+ def present_roles *roles
21
+ roles.map{|role| extract_role role}
22
+ end
23
+
24
+ def set_empty_role
25
+ self.send("#{role_attribute}=", nil)
26
+ end
27
+ end
28
+
29
+ extend Roles::Generic::User::Configuration
30
+ configure :num => :single, :type => :role_class
31
+
32
+ def self.included(base)
33
+ base.extend Roles::Generic::Role::ClassMethods
34
+ end
35
+
36
+ include Roles::Generic::User::Implementation::Single
37
+ end
38
+ end
@@ -3,7 +3,7 @@ require 'sugar-high/array'
3
3
 
4
4
  module Roles::Strategy
5
5
  class << self
6
- NON_INLINE_STRATEGIES = [:one_role, :many_roles]
6
+ NON_INLINE_STRATEGIES = [:one_role, :many_roles, :embed_one_role, :embed_many_roles]
7
7
 
8
8
  def role_dir
9
9
  File.dirname(__FILE__)
@@ -12,6 +12,10 @@ module Roles::Strategy
12
12
  def gem_name
13
13
  :roles_generic
14
14
  end
15
+
16
+ def embedded? strategy
17
+ strategy.to_s.include? 'embed'
18
+ end
15
19
 
16
20
  def role_strategies cardinality
17
21
  pattern = role_dir + "/strategy/#{cardinality}/*.rb"
@@ -41,6 +45,7 @@ def use_roles_strategy strategy
41
45
  require "roles_generic/admin" if strategy =~ /admin/
42
46
 
43
47
  gem_name = Roles::Strategy.gem_name
44
- require "#{gem_name}/role" if !Roles::Strategy.inline_strategy? strategy
48
+ prefix = Roles::Strategy.embedded?(strategy) ? 'embedded_' : ''
49
+ require "#{gem_name}/#{prefix}role" if !Roles::Strategy.inline_strategy?(strategy)
45
50
  require "#{gem_name}/strategy/#{cardinality}/#{strategy}"
46
51
  end
@@ -1,107 +1,107 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_generic}
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-11-20}
12
+ s.date = %q{2010-12-26}
13
13
  s.description = %q{Generic role strategies sharing the same API. Easy to insert in any model}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.markdown"
17
+ "README.textile"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- ".rspec",
23
- "LICENSE",
24
- "README.markdown",
25
- "Rakefile",
26
- "VERSION",
27
- "lib/generators/roles_generic/roles/roles_generator.rb",
28
- "lib/roles_generic.rb",
29
- "lib/roles_generic/admin.rb",
30
- "lib/roles_generic/base.rb",
31
- "lib/roles_generic/generic.rb",
32
- "lib/roles_generic/generic/role.rb",
33
- "lib/roles_generic/generic/role_util.rb",
34
- "lib/roles_generic/generic/user.rb",
35
- "lib/roles_generic/generic/user/class_methods.rb",
36
- "lib/roles_generic/generic/user/configuration.rb",
37
- "lib/roles_generic/generic/user/implementation.rb",
38
- "lib/roles_generic/generic/user/multi_impl.rb",
39
- "lib/roles_generic/generic/user/single_impl.rb",
40
- "lib/roles_generic/namespaces.rb",
41
- "lib/roles_generic/role.rb",
42
- "lib/roles_generic/rspec/api/completeness.rb",
43
- "lib/roles_generic/rspec/api/full.rb",
44
- "lib/roles_generic/rspec/api/read_api.rb",
45
- "lib/roles_generic/rspec/api/simple_check.rb",
46
- "lib/roles_generic/rspec/api/user_class_api.rb",
47
- "lib/roles_generic/rspec/api/write_api.rb",
48
- "lib/roles_generic/rspec/test_it.rb",
49
- "lib/roles_generic/rspec/user_setup.rb",
50
- "lib/roles_generic/strategy.rb",
51
- "lib/roles_generic/strategy/multi/many_roles.rb",
52
- "lib/roles_generic/strategy/multi/role_strings.rb",
53
- "lib/roles_generic/strategy/multi/roles_mask.rb",
54
- "lib/roles_generic/strategy/multi/roles_string.rb",
55
- "lib/roles_generic/strategy/single/admin_flag.rb",
56
- "lib/roles_generic/strategy/single/one_role.rb",
57
- "lib/roles_generic/strategy/single/role_string.rb",
58
- "roles_generic.gemspec",
59
- "spec/generator_spec_helper.rb",
60
- "spec/roles_generic/generators/admin_flag_generator_spec.rb",
61
- "spec/roles_generic/generators/many_roles_generator_spec.rb",
62
- "spec/roles_generic/generators/one_role_generator_spec.rb",
63
- "spec/roles_generic/generators/role_string_generator_spec.rb",
64
- "spec/roles_generic/generators/role_strings_generator_spec.rb",
65
- "spec/roles_generic/generators/roles_mask_generator_spec.rb",
66
- "spec/roles_generic/generators/roles_string_generator_spec.rb",
67
- "spec/roles_generic/strategy/multi/many_roles_spec.rb",
68
- "spec/roles_generic/strategy/multi/role_strings_spec.rb",
69
- "spec/roles_generic/strategy/multi/roles_mask_spec.rb",
70
- "spec/roles_generic/strategy/multi/roles_string_spec.rb",
71
- "spec/roles_generic/strategy/single/admin_flag_spec.rb",
72
- "spec/roles_generic/strategy/single/one_role_spec.rb",
73
- "spec/roles_generic/strategy/single/role_string_spec.rb",
74
- "spec/spec_helper.rb",
75
- "wiki/strategies/admin_flag.textile",
76
- "wiki/strategies/many_roles.textile",
77
- "wiki/strategies/one_role.textile",
78
- "wiki/strategies/role_string.textile",
79
- "wiki/strategies/role_strings.textile",
80
- "wiki/strategies/roles_mask.textile",
81
- "wiki/strategies/roles_string.textile"
21
+ ".rspec",
22
+ "LICENSE",
23
+ "README.textile",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/generators/roles_generic/roles/roles_generator.rb",
27
+ "lib/roles_generic.rb",
28
+ "lib/roles_generic/admin.rb",
29
+ "lib/roles_generic/base.rb",
30
+ "lib/roles_generic/generic.rb",
31
+ "lib/roles_generic/generic/role.rb",
32
+ "lib/roles_generic/generic/role_util.rb",
33
+ "lib/roles_generic/generic/user.rb",
34
+ "lib/roles_generic/generic/user/class_methods.rb",
35
+ "lib/roles_generic/generic/user/configuration.rb",
36
+ "lib/roles_generic/generic/user/implementation.rb",
37
+ "lib/roles_generic/generic/user/multi_impl.rb",
38
+ "lib/roles_generic/generic/user/single_impl.rb",
39
+ "lib/roles_generic/namespaces.rb",
40
+ "lib/roles_generic/role.rb",
41
+ "lib/roles_generic/rspec/api/completeness.rb",
42
+ "lib/roles_generic/rspec/api/full.rb",
43
+ "lib/roles_generic/rspec/api/read_api.rb",
44
+ "lib/roles_generic/rspec/api/simple_check.rb",
45
+ "lib/roles_generic/rspec/api/user_class_api.rb",
46
+ "lib/roles_generic/rspec/api/write_api.rb",
47
+ "lib/roles_generic/rspec/test_it.rb",
48
+ "lib/roles_generic/rspec/user_setup.rb",
49
+ "lib/roles_generic/strategy.rb",
50
+ "lib/roles_generic/strategy/multi/embed_many_roles.rb",
51
+ "lib/roles_generic/strategy/multi/many_roles.rb",
52
+ "lib/roles_generic/strategy/multi/role_strings.rb",
53
+ "lib/roles_generic/strategy/multi/roles_mask.rb",
54
+ "lib/roles_generic/strategy/multi/roles_string.rb",
55
+ "lib/roles_generic/strategy/single/admin_flag.rb",
56
+ "lib/roles_generic/strategy/single/embed_one_role.rb",
57
+ "lib/roles_generic/strategy/single/one_role.rb",
58
+ "lib/roles_generic/strategy/single/role_string.rb",
59
+ "roles_generic.gemspec",
60
+ "spec/generator_spec_helper.rb",
61
+ "spec/roles_generic/generators/admin_flag_generator_spec.rb",
62
+ "spec/roles_generic/generators/many_roles_generator_spec.rb",
63
+ "spec/roles_generic/generators/one_role_generator_spec.rb",
64
+ "spec/roles_generic/generators/role_string_generator_spec.rb",
65
+ "spec/roles_generic/generators/role_strings_generator_spec.rb",
66
+ "spec/roles_generic/generators/roles_mask_generator_spec.rb",
67
+ "spec/roles_generic/generators/roles_string_generator_spec.rb",
68
+ "spec/roles_generic/strategy/multi/many_roles_spec.rb",
69
+ "spec/roles_generic/strategy/multi/role_strings_spec.rb",
70
+ "spec/roles_generic/strategy/multi/roles_mask_spec.rb",
71
+ "spec/roles_generic/strategy/multi/roles_string_spec.rb",
72
+ "spec/roles_generic/strategy/single/admin_flag_spec.rb",
73
+ "spec/roles_generic/strategy/single/one_role_spec.rb",
74
+ "spec/roles_generic/strategy/single/role_string_spec.rb",
75
+ "spec/spec_helper.rb",
76
+ "wiki/strategies/admin_flag.textile",
77
+ "wiki/strategies/many_roles.textile",
78
+ "wiki/strategies/one_role.textile",
79
+ "wiki/strategies/role_string.textile",
80
+ "wiki/strategies/role_strings.textile",
81
+ "wiki/strategies/roles_mask.textile",
82
+ "wiki/strategies/roles_string.textile"
82
83
  ]
83
- s.homepage = %q{http://github.com/kristianmandrup/roles_for_mm}
84
- s.rdoc_options = ["--charset=UTF-8"]
84
+ s.homepage = %q{http://github.com/kristianmandrup/roles_generic}
85
85
  s.require_paths = ["lib"]
86
86
  s.rubygems_version = %q{1.3.7}
87
87
  s.summary = %q{Generic role strategies sharing the same API}
88
88
  s.test_files = [
89
89
  "spec/generator_spec_helper.rb",
90
- "spec/roles_generic/generators/admin_flag_generator_spec.rb",
91
- "spec/roles_generic/generators/many_roles_generator_spec.rb",
92
- "spec/roles_generic/generators/one_role_generator_spec.rb",
93
- "spec/roles_generic/generators/role_string_generator_spec.rb",
94
- "spec/roles_generic/generators/role_strings_generator_spec.rb",
95
- "spec/roles_generic/generators/roles_mask_generator_spec.rb",
96
- "spec/roles_generic/generators/roles_string_generator_spec.rb",
97
- "spec/roles_generic/strategy/multi/many_roles_spec.rb",
98
- "spec/roles_generic/strategy/multi/role_strings_spec.rb",
99
- "spec/roles_generic/strategy/multi/roles_mask_spec.rb",
100
- "spec/roles_generic/strategy/multi/roles_string_spec.rb",
101
- "spec/roles_generic/strategy/single/admin_flag_spec.rb",
102
- "spec/roles_generic/strategy/single/one_role_spec.rb",
103
- "spec/roles_generic/strategy/single/role_string_spec.rb",
104
- "spec/spec_helper.rb"
90
+ "spec/roles_generic/generators/admin_flag_generator_spec.rb",
91
+ "spec/roles_generic/generators/many_roles_generator_spec.rb",
92
+ "spec/roles_generic/generators/one_role_generator_spec.rb",
93
+ "spec/roles_generic/generators/role_string_generator_spec.rb",
94
+ "spec/roles_generic/generators/role_strings_generator_spec.rb",
95
+ "spec/roles_generic/generators/roles_mask_generator_spec.rb",
96
+ "spec/roles_generic/generators/roles_string_generator_spec.rb",
97
+ "spec/roles_generic/strategy/multi/many_roles_spec.rb",
98
+ "spec/roles_generic/strategy/multi/role_strings_spec.rb",
99
+ "spec/roles_generic/strategy/multi/roles_mask_spec.rb",
100
+ "spec/roles_generic/strategy/multi/roles_string_spec.rb",
101
+ "spec/roles_generic/strategy/single/admin_flag_spec.rb",
102
+ "spec/roles_generic/strategy/single/one_role_spec.rb",
103
+ "spec/roles_generic/strategy/single/role_string_spec.rb",
104
+ "spec/spec_helper.rb"
105
105
  ]
106
106
 
107
107
  if s.respond_to? :specification_version then
@@ -109,29 +109,29 @@ Gem::Specification.new do |s|
109
109
  s.specification_version = 3
110
110
 
111
111
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
112
- s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
113
- s.add_development_dependency(%q<generator-spec>, [">= 0.7"])
112
+ s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
113
+ s.add_development_dependency(%q<generator-spec>, [">= 0.7.2"])
114
114
  s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
115
- s.add_runtime_dependency(%q<activesupport>, [">= 3.0"])
116
- s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
117
- s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
115
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.1"])
116
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.1"])
117
+ s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.3.2"])
118
118
  s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.6"])
119
119
  else
120
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
121
- s.add_dependency(%q<generator-spec>, [">= 0.7"])
120
+ s.add_dependency(%q<rspec>, [">= 2.0.1"])
121
+ s.add_dependency(%q<generator-spec>, [">= 0.7.2"])
122
122
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
123
- s.add_dependency(%q<activesupport>, [">= 3.0"])
124
- s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
125
- s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
123
+ s.add_dependency(%q<activesupport>, [">= 3.0.1"])
124
+ s.add_dependency(%q<sugar-high>, ["~> 0.3.1"])
125
+ s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.2"])
126
126
  s.add_dependency(%q<logging_assist>, [">= 0.1.6"])
127
127
  end
128
128
  else
129
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
130
- s.add_dependency(%q<generator-spec>, [">= 0.7"])
129
+ s.add_dependency(%q<rspec>, [">= 2.0.1"])
130
+ s.add_dependency(%q<generator-spec>, [">= 0.7.2"])
131
131
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
132
- s.add_dependency(%q<activesupport>, [">= 3.0"])
133
- s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
134
- s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
132
+ s.add_dependency(%q<activesupport>, [">= 3.0.1"])
133
+ s.add_dependency(%q<sugar-high>, ["~> 0.3.1"])
134
+ s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.2"])
135
135
  s.add_dependency(%q<logging_assist>, [">= 0.1.6"])
136
136
  end
137
137
  end
@@ -1,13 +1,11 @@
1
1
  require 'spec_helper'
2
- use_roles_strategy :many_roles
3
2
 
4
3
  class User
5
4
  include Roles::Generic
6
- strategy :many_roles, :default
7
5
 
8
- role_class :role
9
6
  attr_accessor :name
10
7
 
8
+ strategy :many_roles
11
9
  valid_roles_are :admin, :user, :guest
12
10
 
13
11
  def initialize name, *new_roles
@@ -1,12 +1,10 @@
1
1
  require 'spec_helper'
2
- use_roles_strategy :role_strings
3
-
4
2
  class User
5
3
  include Roles::Generic
6
4
 
7
5
  attr_accessor :name
8
6
 
9
- strategy :role_strings, :default
7
+ strategy :role_strings
10
8
  valid_roles_are :admin, :user, :guest
11
9
 
12
10
  def initialize name, *new_roles
@@ -1,12 +1,10 @@
1
1
  require 'spec_helper'
2
- use_roles_strategy :roles_mask
3
-
4
2
  class User
5
3
  include Roles::Generic
6
4
 
7
5
  attr_accessor :name
8
6
 
9
- strategy :roles_mask, :default
7
+ strategy :roles_mask
10
8
  valid_roles_are :admin, :user, :guest
11
9
 
12
10
  def initialize name, *new_roles
@@ -1,12 +1,10 @@
1
1
  require 'spec_helper'
2
- use_roles_strategy :roles_string
3
-
4
2
  class User
5
3
  include Roles::Generic
6
4
 
7
5
  attr_accessor :name
8
6
 
9
- strategy :roles_string, :default
7
+ strategy :roles_string
10
8
  valid_roles_are :admin, :user, :guest
11
9
 
12
10
  def initialize name, *new_roles
@@ -1,12 +1,10 @@
1
1
  require 'spec_helper'
2
- use_roles_strategy :admin_flag
3
-
4
2
  class User
5
3
  include Roles::Generic
6
4
 
7
5
  attr_accessor :name
8
6
 
9
- strategy :admin_flag, :default
7
+ strategy :admin_flag
10
8
  valid_roles_are :admin, :user, :guest
11
9
 
12
10
  def initialize name, *new_roles
@@ -1,13 +1,10 @@
1
1
  require 'spec_helper'
2
- use_roles_strategy :one_role
3
-
4
2
  class User
5
3
  include Roles::Generic
6
- strategy :one_role, :default
7
4
 
8
- role_class :role
9
5
  attr_accessor :name
10
6
 
7
+ strategy :one_role
11
8
  valid_roles_are :admin, :user, :guest
12
9
 
13
10
  def initialize name, *new_roles
@@ -1,12 +1,10 @@
1
1
  require 'spec_helper'
2
- use_roles_strategy :role_string
3
-
4
2
  class User
5
3
  include Roles::Generic
6
4
 
7
5
  attr_accessor :name
8
6
 
9
- strategy :role_string, :default
7
+ strategy :role_string
10
8
  valid_roles_are :admin, :user, :guest
11
9
 
12
10
  def initialize name, *new_roles
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 3
9
- version: 0.3.3
8
+ - 4
9
+ version: 0.3.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-20 00:00:00 +01:00
17
+ date: 2010-12-26 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -28,8 +28,8 @@ dependencies:
28
28
  segments:
29
29
  - 2
30
30
  - 0
31
- - 0
32
- version: 2.0.0
31
+ - 1
32
+ version: 2.0.1
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -43,7 +43,8 @@ dependencies:
43
43
  segments:
44
44
  - 0
45
45
  - 7
46
- version: "0.7"
46
+ - 2
47
+ version: 0.7.2
47
48
  type: :development
48
49
  version_requirements: *id002
49
50
  - !ruby/object:Gem::Dependency
@@ -72,7 +73,8 @@ dependencies:
72
73
  segments:
73
74
  - 3
74
75
  - 0
75
- version: "3.0"
76
+ - 1
77
+ version: 3.0.1
76
78
  type: :runtime
77
79
  version_requirements: *id004
78
80
  - !ruby/object:Gem::Dependency
@@ -86,8 +88,8 @@ dependencies:
86
88
  segments:
87
89
  - 0
88
90
  - 3
89
- - 0
90
- version: 0.3.0
91
+ - 1
92
+ version: 0.3.1
91
93
  type: :runtime
92
94
  version_requirements: *id005
93
95
  - !ruby/object:Gem::Dependency
@@ -101,8 +103,8 @@ dependencies:
101
103
  segments:
102
104
  - 0
103
105
  - 3
104
- - 1
105
- version: 0.3.1
106
+ - 2
107
+ version: 0.3.2
106
108
  type: :runtime
107
109
  version_requirements: *id006
108
110
  - !ruby/object:Gem::Dependency
@@ -128,13 +130,12 @@ extensions: []
128
130
 
129
131
  extra_rdoc_files:
130
132
  - LICENSE
131
- - README.markdown
133
+ - README.textile
132
134
  files:
133
135
  - .document
134
- - .gitignore
135
136
  - .rspec
136
137
  - LICENSE
137
- - README.markdown
138
+ - README.textile
138
139
  - Rakefile
139
140
  - VERSION
140
141
  - lib/generators/roles_generic/roles/roles_generator.rb
@@ -161,11 +162,13 @@ files:
161
162
  - lib/roles_generic/rspec/test_it.rb
162
163
  - lib/roles_generic/rspec/user_setup.rb
163
164
  - lib/roles_generic/strategy.rb
165
+ - lib/roles_generic/strategy/multi/embed_many_roles.rb
164
166
  - lib/roles_generic/strategy/multi/many_roles.rb
165
167
  - lib/roles_generic/strategy/multi/role_strings.rb
166
168
  - lib/roles_generic/strategy/multi/roles_mask.rb
167
169
  - lib/roles_generic/strategy/multi/roles_string.rb
168
170
  - lib/roles_generic/strategy/single/admin_flag.rb
171
+ - lib/roles_generic/strategy/single/embed_one_role.rb
169
172
  - lib/roles_generic/strategy/single/one_role.rb
170
173
  - lib/roles_generic/strategy/single/role_string.rb
171
174
  - roles_generic.gemspec
@@ -193,12 +196,12 @@ files:
193
196
  - wiki/strategies/roles_mask.textile
194
197
  - wiki/strategies/roles_string.textile
195
198
  has_rdoc: true
196
- homepage: http://github.com/kristianmandrup/roles_for_mm
199
+ homepage: http://github.com/kristianmandrup/roles_generic
197
200
  licenses: []
198
201
 
199
202
  post_install_message:
200
- rdoc_options:
201
- - --charset=UTF-8
203
+ rdoc_options: []
204
+
202
205
  require_paths:
203
206
  - lib
204
207
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
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/README.markdown DELETED
@@ -1,178 +0,0 @@
1
- # Generic Roles
2
-
3
- Generic Roles is a common (generic) Roles API and implementation that specific Roles implementations for various ORMs can implement.
4
- This library also comes with a Rails 3 generator that can configure an existing user model with a Role strategy of choice.
5
- A similar generator should always be created for specific ORM implementations
6
-
7
- I have developed the following *roles* gems for popular Object Mappers that all support the same Roles Generic API.
8
-
9
- Relational Database (SQL)
10
- * Active Record - [roles_active_record](http://github.com/kristianmandrup/roles_active_record)
11
- * Data Mapper - [roles_data_mapper](http://github.com/kristianmandrup/roles_data_mapper)
12
-
13
- Mongo DB
14
- * Mongoid - [roles_mongoid](http://github.com/kristianmandrup/roles_mongoid)
15
- * Mongo Mapper - [roles_mongo_mapper](http://github.com/kristianmandrup/roles_mongo_mapper)
16
-
17
- Couch DB
18
- * Simply Stored - [roles_simply_stored](http://github.com/kristianmandrup/roles_simply_stored)
19
-
20
- Note: Feel free to roll your own ORM extension for your favorite Object Mapper!
21
-
22
- ## Install
23
-
24
- <code>gem install roles_generic</code>
25
-
26
- ## Roles generator
27
-
28
- A Rails 3 generator is included to update an existing model with a roles strategy and a set of valid roles
29
-
30
- ### Usage example
31
-
32
- <code>rails g roles_generic:roles --strategy admin_flag --roles guest admin</code>
33
-
34
- This generator is currently (Oct. 10) experimental. Feel free to provide patches or bug reports ;)
35
-
36
- ## Usage
37
-
38
- The library comes with the following role models built-in:
39
-
40
- Inline roles (in User model):
41
- * admin_flag (Boolean flag - 'admin' or not)
42
- * role_string (String)
43
- * roles_string (Comma separated String - note: no role name must have a comma in its name!)
44
- * role_strings (Set of Strings)
45
- * roles_mask (Integer mask)
46
-
47
- Using separate Role model:
48
- * one_role (relation to a Role model instance)
49
- * many_roles(Set of Role relationships)
50
-
51
- Note: The following examples use RSpec to demonstrate usage scenarios.
52
-
53
- Examples of configuring for the other strategies can be found on the wiki pages.
54
-
55
- ## Example : admin_flag
56
-
57
- Creates and uses a binary field 'admin_flag', which when true signals that this user is an administrator and otherwise a normal user.
58
-
59
- <pre>
60
- class User
61
- include Roles::Generic
62
-
63
- attr_accessor :name, :admin_flag
64
-
65
- role_strategy :admin_flag, :default
66
-
67
- roles :admin, :user
68
-
69
- def initialize name, *new_roles
70
- self.name = name
71
- self.roles = new_roles
72
- end
73
- end
74
- </pre>
75
-
76
- ## Example: Using an Object Mapper
77
-
78
- Data Mapper with persistent attributes :name and :admin_flag
79
-
80
- <pre>
81
- class User
82
- include Roles::Generic
83
- include DataMapper::Resource
84
-
85
- property :name, Boolean
86
- property :admin_flag, Boolean
87
-
88
- role_strategy :admin_flag, :default
89
-
90
- roles :admin, :user
91
-
92
- def initialize name, *new_roles
93
- self.name = name
94
- self.roles = new_roles
95
- end
96
- end
97
- </pre>
98
-
99
- _Note:_ I recommend using s specific ORM roles gem such as *roles_data_mapper* instead. But this approach might be a good starting point for developing a *roles* gem for an ORM that is not supported ;)
100
-
101
- ## Role API
102
-
103
- ### Instance methods
104
-
105
- Has ALL of the given roles been assigned?
106
- * has_roles?(*roles) - alias: is?
107
-
108
- Has ANY (at least ONE) of the given roles been assigned?
109
- * has_role? *roles - alias: has?
110
-
111
- Is this a valid role? (can the role be found in list of valid roles?)
112
- * valid_role? role
113
-
114
- Is this user the admin user (and user has no other roles)
115
- * admin? - short for - is?(:admin)
116
-
117
- ### Class methods
118
-
119
- * roles - list of valid roles
120
- * roles_attribute - get the attribute where the role is stored on the user
121
- * roles_attribute= - set the role(s) attribute
122
-
123
- ## Usage of API
124
-
125
- <pre>
126
- before :each do
127
- @admin_user = User.new 'Admin user', :admin
128
- @guest = User.new 'Guest', :guest
129
- end
130
-
131
- it "user 'Admin user' should have role :admin" do
132
-
133
- @admin_user.role.should == :admin
134
- @admin_user.roles.should == [:admin]
135
- @admin_user.admin?.should be_true
136
-
137
- @admin_user.has_role? (:user).should be_false
138
-
139
- @admin_user.has_role? (:admin).should be_true
140
- @admin_user.is? (:admin).should be_true
141
- @admin_user.has_roles? (:admin).should be_true
142
- @admin_user.has? (:admin).should be_true
143
-
144
- end
145
-
146
- it "user Guest should have role :guest" do
147
- @guest.roles.should == [:guest]
148
- @guest.admin?.should be_false
149
-
150
- @guest.has_role? (:guest).should be_true
151
- @guest.has_role? (:admin).should be_false
152
- @guest.is? (:admin).should be_false
153
-
154
- @guest.has_roles? (:guest).should be_true
155
- @guest.has? (:admin).should be_false
156
- end
157
-
158
- it "should set role of Guest user from :guest to :admin using roles=" do
159
- @guest.roles = :admin
160
- @guest.role.should == :admin
161
-
162
- @guest.has_role?(:admin).should be_true
163
- end
164
- </pre>
165
-
166
- ## Note on Patches/Pull Requests
167
-
168
- * Fork the project.
169
- * Make your feature addition or bug fix.
170
- * Add tests for it. This is important so I don't break it in a
171
- future version unintentionally.
172
- * Commit, do not mess with rakefile, version, or history.
173
- (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)
174
- * Send me a pull request. Bonus points for topic branches.
175
-
176
- ## Copyright
177
-
178
- Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.