the_role 2.0.4 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d1fe7a9a634b09aac64fa6ee91b0508785b9586d
4
+ data.tar.gz: a07bb7473cd3f2023f8ba2642345c1fda8c95c61
5
+ SHA512:
6
+ metadata.gz: d9dd558bf8605e39cfb74d0aedc35bf737c8da9d8b6ec5a21b1190e1ca52011551137e0d14ae4d8b503f89aae926ed6d1f344969acd361ca292b3be045d0ffb4
7
+ data.tar.gz: a9c9c751e67ce55f69af149fafafdb17bd26a63d1c92b72e2cc3adf867cab416961b7be0fad7e7f98e2158891430264929258b96e63a39681b6c228c7a94ea9a
data/.travis.yml CHANGED
@@ -2,4 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  gemfile: spec/the_role_on_devise/Gemfile
5
- script: "cd spec/the_role_on_devise && bin/rake db:drop RAILS_ENV=test && bin/rake db:create RAILS_ENV=test && bin/rake db:migrate RAILS_ENV=test && bundle exec rspec --format documentation"
5
+ script: "cd spec/the_role_on_devise && rake db:bootstrap RAILS_ENV=test && rspec --format documentation"
@@ -5,6 +5,7 @@ module RoleModel
5
5
 
6
6
  def role_hash; to_hash; end
7
7
  alias_method :has?, :has_role?
8
+ alias_method :any?, :any_role?
8
9
 
9
10
  def has_section? section_name
10
11
  to_hash.key? TheRoleParam.process(section_name)
@@ -19,6 +19,11 @@ module TheRoleBase
19
19
  hash[section_name][rule_name]
20
20
  end
21
21
 
22
+ def any_role? roles_hash = {}
23
+ roles_hash.each_pair{|section, action| return true if has_role?(section, action)}
24
+ false
25
+ end
26
+
22
27
  def moderator? section_name
23
28
  section_name = TheRoleParam.process(section_name)
24
29
  has_role? section_name, 'any_crazy_name'
@@ -6,24 +6,27 @@ Description:
6
6
  This generators helps to install TheRole gem into your Application
7
7
 
8
8
  This text:
9
- bundle exec rails g the_role --help
9
+ > bundle exec rails g the_role --help
10
10
 
11
11
  Generators:
12
- bundle exec rails g the_role install
12
+ > bundle exec rails g the_role install
13
13
  - Install config file and models
14
14
 
15
- bundle exec rails g the_role setup
15
+ > bundle exec rails g the_role setup
16
16
  - Install config file
17
17
 
18
- bundle exec rails g the_role models
18
+ > bundle exec rails g the_role models
19
19
  - Install models
20
20
 
21
- bundle exec rails g the_role admin
21
+ > bundle exec rails g the_role admin
22
+ - Create Admin Role
23
+
24
+ > rake db:roles:admin
22
25
  - Create Admin Role
23
26
 
24
27
  Migrations:
25
- bundle exec rake the_role_engine:install:migrations
28
+ > bundle exec rake the_role_engine:install:migrations
26
29
 
27
30
  ---------------------------------------
28
- TheRole
31
+ ~ TheRole
29
32
  ---------------------------------------
data/lib/tasks/roles.rake CHANGED
@@ -1,23 +1,47 @@
1
1
  namespace :db do
2
2
  namespace :roles do
3
+ # rake db:roles:admin
4
+ desc 'create Admin Role'
5
+ task :admin => :environment do
6
+ puts `clear`
7
+ puts '~'*40
8
+ puts 'TheRole'
9
+ puts '~'*40
10
+
11
+ unless Role.with_name(:admin)
12
+ role = Role.create(
13
+ name: :admin,
14
+ title: "Role for admin",
15
+ description:"This user can do anything"
16
+ )
17
+
18
+ role.create_rule(:system, :administrator)
19
+ role.rule_on(:system, :administrator)
20
+
21
+ puts "Admin role created"
22
+ else
23
+ puts "Admin role exists"
24
+ end
25
+
26
+ puts "Now you can makes any user as Admin:"
27
+ puts "> rails c"
28
+ puts "> User.first.update( role: Role.with_name(:admin) )"
29
+ puts '~'*40
30
+ end
3
31
 
4
32
  # rake db:roles:test
5
33
  desc 'create roles'
6
34
  task :test => :environment do
7
35
  # ADMIN
8
- role = {
9
- :system => {
10
- :administrator => true
11
- }
12
- }
13
-
14
- Role.create!(
15
- :name => :admin,
16
- :title => 'Administrator',
17
- :description => 'Role for administrator',
18
- :the_role => role.to_json
36
+ role = Role.create(
37
+ name: :admin,
38
+ title: "Role for admin",
39
+ description:"This user can do anything"
19
40
  )
20
41
 
42
+ role.create_rule(:system, :administrator)
43
+ role.rule_on(:system, :administrator)
44
+
21
45
  puts 'Administrator'
22
46
 
23
47
  # MODERATOR
@@ -1,3 +1,3 @@
1
1
  module TheRole
2
- VERSION = "2.0.4"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,27 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_role
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
5
- prerelease:
4
+ version: 2.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ilya N. Zykin [the-teacher]
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-28 00:00:00.000000000 Z
11
+ date: 2013-08-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: haml
16
- requirement: &77484780 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *77484780
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  description: Authorization for Rails 4 with Web Interface
26
28
  email:
27
29
  - zykin-ilya@ya.ru
@@ -70,26 +72,25 @@ files:
70
72
  - the_role.gemspec
71
73
  homepage: https://github.com/the-teacher/the_role
72
74
  licenses: []
75
+ metadata: {}
73
76
  post_install_message:
74
77
  rdoc_options: []
75
78
  require_paths:
76
79
  - lib
77
80
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
81
  requirements:
80
82
  - - ! '>='
81
83
  - !ruby/object:Gem::Version
82
84
  version: '0'
83
85
  required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
86
  requirements:
86
87
  - - ! '>='
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  requirements: []
90
91
  rubyforge_project: the_role
91
- rubygems_version: 1.8.15
92
+ rubygems_version: 2.0.5
92
93
  signing_key:
93
- specification_version: 3
94
+ specification_version: 4
94
95
  summary: Authorization for Rails 4
95
96
  test_files: []