monarchy 2.1.0 → 2.2.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -1
  3. data/Gemfile +6 -5
  4. data/Gemfile.lock +55 -55
  5. data/Rakefile +1 -0
  6. data/app/models/monarchy/hierarchy.rb +1 -0
  7. data/app/models/monarchy/member.rb +1 -0
  8. data/app/models/monarchy/members_role.rb +1 -0
  9. data/app/models/monarchy/role.rb +1 -0
  10. data/docs/acts_as_hierarchy.md +9 -0
  11. data/docs/acts_as_resource.md +8 -0
  12. data/dummy/Rakefile +1 -0
  13. data/dummy/app/controllers/application_controller.rb +1 -0
  14. data/dummy/app/helpers/application_helper.rb +1 -0
  15. data/dummy/app/models/member.rb +1 -0
  16. data/dummy/app/models/memo.rb +1 -0
  17. data/dummy/app/models/project.rb +1 -0
  18. data/dummy/app/models/resource.rb +1 -0
  19. data/dummy/app/models/role.rb +1 -0
  20. data/dummy/app/models/status.rb +1 -0
  21. data/dummy/app/models/task.rb +1 -0
  22. data/dummy/app/models/user.rb +1 -0
  23. data/dummy/bin/bundle +1 -0
  24. data/dummy/bin/rails +1 -0
  25. data/dummy/bin/rake +1 -0
  26. data/dummy/bin/setup +1 -0
  27. data/dummy/config/application.rb +1 -0
  28. data/dummy/config/boot.rb +1 -0
  29. data/dummy/config/environment.rb +1 -0
  30. data/dummy/config/environments/development.rb +1 -0
  31. data/dummy/config/environments/production.rb +1 -0
  32. data/dummy/config/environments/test.rb +1 -0
  33. data/dummy/config/initializers/assets.rb +1 -0
  34. data/dummy/config/initializers/cookies_serializer.rb +1 -0
  35. data/dummy/config/initializers/filter_parameter_logging.rb +1 -0
  36. data/dummy/config/initializers/monarchy.rb +1 -0
  37. data/dummy/config/initializers/session_store.rb +1 -0
  38. data/dummy/config/initializers/wrap_parameters.rb +1 -0
  39. data/dummy/config/routes.rb +1 -0
  40. data/dummy/config.ru +1 -0
  41. data/lib/generators/monarchy/resource_generator.rb +1 -0
  42. data/lib/generators/monarchy/setup_generator.rb +1 -0
  43. data/lib/monarchy/acts_as_hierarchy.rb +9 -0
  44. data/lib/monarchy/acts_as_member.rb +2 -1
  45. data/lib/monarchy/acts_as_resource.rb +5 -0
  46. data/lib/monarchy/acts_as_role.rb +1 -0
  47. data/lib/monarchy/acts_as_user.rb +2 -1
  48. data/lib/monarchy/engine.rb +1 -0
  49. data/lib/monarchy/exceptions.rb +1 -0
  50. data/lib/monarchy/tasks.rb +1 -0
  51. data/lib/monarchy/validators.rb +1 -0
  52. data/lib/monarchy/version.rb +2 -1
  53. data/lib/monarchy.rb +1 -0
  54. data/monarchy.gemspec +3 -2
  55. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c1b86d97c67b9409578191ef62d270fb906dec7
4
- data.tar.gz: 77e1921b3153f9ebd4ec32a7a025efae77c9ec05
3
+ metadata.gz: 4734b0ccb0db7937722f2fa64a0bbe4d47c65cb7
4
+ data.tar.gz: f7b5fa3002944a30b7eba6e2404c958c4c0762d9
5
5
  SHA512:
6
- metadata.gz: a25851a0766ad737e3707026aae70160d28077de7c545bdfea6e1b0645bad7ecd460c90192162632c80a2d860944e5f462799660dc2af9c59542779dc4b8ebe5
7
- data.tar.gz: e1ad1bf1ee4f3f6eca2c722a30fb38e1efd1e61dcae631506b54c6554dba33e4ca6a257e72faba47df681a9deeb1d80f4efe6c8816f6dfd9dc3cd41bcc7614cf
6
+ metadata.gz: 9f3aa4a7caa467471faa25ff5ed132db52f9c4c82f21786f3191a8d9ad0ebdca134a55cc1bd6927bee27c208cd04bbc0b5716c256d9aa9183ef3246f574524d5
7
+ data.tar.gz: 40faced1c717c0329ea1ce5da56c533ed309e05baac0d3df4e36fec148633c5959775c619fcaf06dbb1738f0704f163f1964b4e8c6296c6444fc5afb8ade4690
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.3
3
3
  Exclude:
4
4
  - 'dummy/db/seeds.rb'
5
5
  - 'dummy/db/migrate/**'
@@ -21,3 +21,9 @@ Style/ClassAndModuleChildren:
21
21
  Enabled: false
22
22
  Rails/HasAndBelongsToMany:
23
23
  Enabled: false
24
+ Style/MixinGrouping:
25
+ Exclude:
26
+ - 'spec/**/*.rb'
27
+ Lint/AmbiguousBlockAssociation:
28
+ Exclude:
29
+ - 'spec/**/*.rb'
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source 'https://rubygems.org'
3
4
  ruby '2.4.0'
4
5
 
@@ -18,14 +19,14 @@ gemspec
18
19
  group :development, :test do
19
20
  gem 'database_cleaner', '1.5.3'
20
21
  gem 'factory_girl_rails', '4.8.0'
21
- gem 'ffaker', '2.4.0'
22
- gem 'pry-rails', '0.3.4'
23
- gem 'rails', '5.0.1'
22
+ gem 'ffaker', '2.5.0'
23
+ gem 'pry-rails', '0.3.6'
24
+ gem 'rails', '5.0.2'
24
25
  gem 'rspec-rails', '3.5.2'
25
- gem 'rubocop', '0.47.1'
26
+ gem 'rubocop', '0.48.0'
26
27
  gem 'shoulda-matchers', '3.1.1'
27
28
  gem 'sqlite3', '1.3.13'
28
29
  end
29
30
 
30
- gem 'codeclimate-test-reporter', '~>1.0.5', group: :test
31
+ gem 'codeclimate-test-reporter', '~>1.0.8', group: :test
31
32
  gem 'simplecov', '0.13.0', group: :test
data/Gemfile.lock CHANGED
@@ -1,51 +1,51 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monarchy (2.1.0)
4
+ monarchy (2.2.0)
5
5
  active_record_union (= 1.2.0)
6
6
  activerecord (>= 4.2.7.1)
7
- closure_tree (= 6.3.0)
7
+ closure_tree (= 6.5.0)
8
8
  configurations (= 2.2.2)
9
9
  tqdm (= 0.3.0)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- actioncable (5.0.1)
15
- actionpack (= 5.0.1)
16
- nio4r (~> 1.2)
14
+ actioncable (5.0.2)
15
+ actionpack (= 5.0.2)
16
+ nio4r (>= 1.2, < 3.0)
17
17
  websocket-driver (~> 0.6.1)
18
- actionmailer (5.0.1)
19
- actionpack (= 5.0.1)
20
- actionview (= 5.0.1)
21
- activejob (= 5.0.1)
18
+ actionmailer (5.0.2)
19
+ actionpack (= 5.0.2)
20
+ actionview (= 5.0.2)
21
+ activejob (= 5.0.2)
22
22
  mail (~> 2.5, >= 2.5.4)
23
23
  rails-dom-testing (~> 2.0)
24
- actionpack (5.0.1)
25
- actionview (= 5.0.1)
26
- activesupport (= 5.0.1)
24
+ actionpack (5.0.2)
25
+ actionview (= 5.0.2)
26
+ activesupport (= 5.0.2)
27
27
  rack (~> 2.0)
28
28
  rack-test (~> 0.6.3)
29
29
  rails-dom-testing (~> 2.0)
30
30
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
31
- actionview (5.0.1)
32
- activesupport (= 5.0.1)
31
+ actionview (5.0.2)
32
+ activesupport (= 5.0.2)
33
33
  builder (~> 3.1)
34
34
  erubis (~> 2.7.0)
35
35
  rails-dom-testing (~> 2.0)
36
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
36
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
37
37
  active_record_union (1.2.0)
38
38
  activerecord (>= 4.0)
39
- activejob (5.0.1)
40
- activesupport (= 5.0.1)
39
+ activejob (5.0.2)
40
+ activesupport (= 5.0.2)
41
41
  globalid (>= 0.3.6)
42
- activemodel (5.0.1)
43
- activesupport (= 5.0.1)
44
- activerecord (5.0.1)
45
- activemodel (= 5.0.1)
46
- activesupport (= 5.0.1)
42
+ activemodel (5.0.2)
43
+ activesupport (= 5.0.2)
44
+ activerecord (5.0.2)
45
+ activemodel (= 5.0.2)
46
+ activesupport (= 5.0.2)
47
47
  arel (~> 7.0)
48
- activesupport (5.0.1)
48
+ activesupport (5.0.2)
49
49
  concurrent-ruby (~> 1.0, >= 1.0.2)
50
50
  i18n (~> 0.7)
51
51
  minitest (~> 5.1)
@@ -53,13 +53,13 @@ GEM
53
53
  arel (7.1.4)
54
54
  ast (2.3.0)
55
55
  builder (3.2.3)
56
- closure_tree (6.3.0)
56
+ closure_tree (6.5.0)
57
57
  activerecord (>= 4.1.0)
58
58
  with_advisory_lock (>= 3.0.0)
59
- codeclimate-test-reporter (1.0.5)
60
- simplecov
59
+ codeclimate-test-reporter (1.0.8)
60
+ simplecov (<= 0.13)
61
61
  coderay (1.1.1)
62
- concurrent-ruby (1.0.4)
62
+ concurrent-ruby (1.0.5)
63
63
  configurations (2.2.2)
64
64
  database_cleaner (1.5.3)
65
65
  diff-lcs (1.3)
@@ -70,10 +70,10 @@ GEM
70
70
  factory_girl_rails (4.8.0)
71
71
  factory_girl (~> 4.8.0)
72
72
  railties (>= 3.0.0)
73
- ffaker (2.4.0)
73
+ ffaker (2.5.0)
74
74
  globalid (0.3.7)
75
75
  activesupport (>= 4.1.0)
76
- i18n (0.8.0)
76
+ i18n (0.8.1)
77
77
  json (2.0.3)
78
78
  loofah (2.0.3)
79
79
  nokogiri (>= 1.5.9)
@@ -85,8 +85,8 @@ GEM
85
85
  mime-types-data (3.2016.0521)
86
86
  mini_portile2 (2.1.0)
87
87
  minitest (5.10.1)
88
- nio4r (1.2.1)
89
- nokogiri (1.7.0.1)
88
+ nio4r (2.0.0)
89
+ nokogiri (1.7.1)
90
90
  mini_portile2 (~> 2.1.0)
91
91
  parser (2.4.0.0)
92
92
  ast (~> 2.2)
@@ -95,31 +95,31 @@ GEM
95
95
  coderay (~> 1.1.0)
96
96
  method_source (~> 0.8.1)
97
97
  slop (~> 3.4)
98
- pry-rails (0.3.4)
99
- pry (>= 0.9.10)
98
+ pry-rails (0.3.6)
99
+ pry (>= 0.10.4)
100
100
  rack (2.0.1)
101
101
  rack-test (0.6.3)
102
102
  rack (>= 1.0)
103
- rails (5.0.1)
104
- actioncable (= 5.0.1)
105
- actionmailer (= 5.0.1)
106
- actionpack (= 5.0.1)
107
- actionview (= 5.0.1)
108
- activejob (= 5.0.1)
109
- activemodel (= 5.0.1)
110
- activerecord (= 5.0.1)
111
- activesupport (= 5.0.1)
103
+ rails (5.0.2)
104
+ actioncable (= 5.0.2)
105
+ actionmailer (= 5.0.2)
106
+ actionpack (= 5.0.2)
107
+ actionview (= 5.0.2)
108
+ activejob (= 5.0.2)
109
+ activemodel (= 5.0.2)
110
+ activerecord (= 5.0.2)
111
+ activesupport (= 5.0.2)
112
112
  bundler (>= 1.3.0, < 2.0)
113
- railties (= 5.0.1)
113
+ railties (= 5.0.2)
114
114
  sprockets-rails (>= 2.0.0)
115
115
  rails-dom-testing (2.0.2)
116
116
  activesupport (>= 4.2.0, < 6.0)
117
117
  nokogiri (~> 1.6)
118
118
  rails-html-sanitizer (1.0.3)
119
119
  loofah (~> 2.0)
120
- railties (5.0.1)
121
- actionpack (= 5.0.1)
122
- activesupport (= 5.0.1)
120
+ railties (5.0.2)
121
+ actionpack (= 5.0.2)
122
+ activesupport (= 5.0.2)
123
123
  method_source
124
124
  rake (>= 0.8.7)
125
125
  thor (>= 0.18.1, < 2.0)
@@ -146,7 +146,7 @@ GEM
146
146
  rspec-mocks (~> 3.5.0)
147
147
  rspec-support (~> 3.5.0)
148
148
  rspec-support (3.5.0)
149
- rubocop (0.47.1)
149
+ rubocop (0.48.0)
150
150
  parser (>= 2.3.3.1, < 3.0)
151
151
  powerpack (~> 0.1)
152
152
  rainbow (>= 1.99.1, < 3.0)
@@ -170,15 +170,15 @@ GEM
170
170
  sprockets (>= 3.0.0)
171
171
  sqlite3 (1.3.13)
172
172
  thor (0.19.4)
173
- thread_safe (0.3.5)
173
+ thread_safe (0.3.6)
174
174
  tqdm (0.3.0)
175
- tzinfo (1.2.2)
175
+ tzinfo (1.2.3)
176
176
  thread_safe (~> 0.1)
177
177
  unicode-display_width (1.1.3)
178
178
  websocket-driver (0.6.5)
179
179
  websocket-extensions (>= 0.1.0)
180
180
  websocket-extensions (0.1.2)
181
- with_advisory_lock (3.0.0)
181
+ with_advisory_lock (3.1.0)
182
182
  activerecord (>= 3.2)
183
183
  thread_safe
184
184
 
@@ -187,17 +187,17 @@ PLATFORMS
187
187
 
188
188
  DEPENDENCIES
189
189
  bundler (~> 1.12)
190
- codeclimate-test-reporter (~> 1.0.5)
190
+ codeclimate-test-reporter (~> 1.0.8)
191
191
  database_cleaner (= 1.5.3)
192
192
  factory_girl_rails (= 4.8.0)
193
- ffaker (= 2.4.0)
193
+ ffaker (= 2.5.0)
194
194
  monarchy!
195
- pry-rails (= 0.3.4)
196
- rails (= 5.0.1)
195
+ pry-rails (= 0.3.6)
196
+ rails (= 5.0.2)
197
197
  rake (~> 12.0)
198
198
  rspec (= 3.5.0)
199
199
  rspec-rails (= 3.5.2)
200
- rubocop (= 0.47.1)
200
+ rubocop (= 0.48.0)
201
201
  shoulda-matchers (= 3.1.1)
202
202
  simplecov (= 0.13.0)
203
203
  sqlite3 (= 1.3.13)
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'bundler/gem_tasks'
3
4
  require 'rspec/core/rake_task'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Monarchy::Hierarchy < ActiveRecord::Base
3
4
  acts_as_hierarchy
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Monarchy::Member < ActiveRecord::Base
3
4
  acts_as_member
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Monarchy::MembersRole < ActiveRecord::Base
3
4
  self.table_name = 'monarchy_members_roles'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Monarchy::Role < ActiveRecord::Base
3
4
  acts_as_role
4
5
  end
@@ -4,6 +4,15 @@
4
4
  > hmm... sounds like `private`
5
5
 
6
6
  ## Methods
7
+
8
+ ### #accessible_for
9
+ You can check if user has an access to the hierarchy by calling `accessible_for(user, options = {})` on hierarchy instance, eg:
10
+ ```ruby
11
+ resource_hierarchy.accessible_for(user) # returns TRUE or FALSE
12
+ ```
13
+
14
+ Optionally, you can pass an `options` argument to specify custom strategy.
15
+
7
16
  ** We do not recommend to use it but if yo have to: **
8
17
  We are using [Closure Tree][e5c808aa] behind `Hierarchy` class. There is a bunch of methods and functions available behind the hood. Check their documentation.
9
18
 
@@ -62,6 +62,14 @@ Returns default role name for the class
62
62
  ### .default_role
63
63
  Returns default role object `Monarchy::Role` for the class
64
64
 
65
+ ### #accessible_for
66
+ You can check if user has an access to the resource by calling `accessible_for(user, options = {})` on resource instance, eg:
67
+ ```ruby
68
+ resource.accessible_for(user) # returns TRUE or FALSE
69
+ ```
70
+
71
+ Optionally, you can pass an `options` argument to specify custom strategy.
72
+
65
73
  ### Scopes:
66
74
 
67
75
  ### .accessible_for
data/dummy/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Add your own tasks in files placed in lib/tasks ending in .rake,
3
4
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class ApplicationController < ActionController::Base
3
4
  # Prevent CSRF attacks by raising an exception.
4
5
  # For APIs, you may want to use :null_session instead.
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ApplicationHelper
3
4
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Member < ActiveRecord::Base
3
4
  acts_as_member
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Memo < ActiveRecord::Base
3
4
  acts_as_resource parent_as: :project
4
5
  belongs_to :project
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Project < ActiveRecord::Base
3
4
  acts_as_resource parent_as: :resource
4
5
  belongs_to :resource
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Resource < ActiveRecord::Base
3
4
  acts_as_resource
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Role < ActiveRecord::Base
3
4
  acts_as_role
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Status < ActiveRecord::Base
3
4
  acts_as_resource parent_as: :project
4
5
  belongs_to :project
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Task < ActiveRecord::Base
3
4
  acts_as_resource parent_as: :resource
4
5
  belongs_to :resource, polymorphic: true
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class User < ActiveRecord::Base
3
4
  acts_as_user
4
5
  end
data/dummy/bin/bundle CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
4
5
  load Gem.bin_path('bundler', 'bundle')
data/dummy/bin/rails CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  APP_PATH = File.expand_path('../../config/application', __FILE__)
4
5
  require_relative '../config/boot'
5
6
  require 'rails/commands'
data/dummy/bin/rake CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  require_relative '../config/boot'
4
5
  require 'rake'
5
6
  Rake.application.run
data/dummy/bin/setup CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
+
3
4
  require 'pathname'
4
5
 
5
6
  # path to your application root.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require File.expand_path('../boot', __FILE__)
3
4
 
4
5
  require 'rails/all'
data/dummy/config/boot.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Set up gems listed in the Gemfile.
3
4
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Load the Rails application.
3
4
  require File.expand_path('../application', __FILE__)
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Rails.application.configure do
3
4
  # Settings specified here will take precedence over those in config/application.rb.
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Rails.application.configure do
3
4
  # Settings specified here will take precedence over those in config/application.rb.
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Rails.application.configure do
3
4
  # Settings specified here will take precedence over those in config/application.rb.
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Be sure to restart your server when you modify this file.
3
4
 
4
5
  # Version of your assets, change this if you want to expire all your assets.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Be sure to restart your server when you modify this file.
3
4
 
4
5
  Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Be sure to restart your server when you modify this file.
3
4
 
4
5
  # Configure sensitive parameters which will be filtered from the log file.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Monarchy.configure do |config|
3
4
  # REQUIRED SETTINGS
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Be sure to restart your server when you modify this file.
3
4
 
4
5
  Rails.application.config.session_store :cookie_store, key: '_dummy_session'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Be sure to restart your server when you modify this file.
3
4
 
4
5
  # This file contains settings for ActionController::ParamsWrapper which
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Rails.application.routes.draw do
3
4
  # The priority is based upon order of creation: first created -> highest priority.
4
5
  # See how all your routes lay out with "rake routes".
data/dummy/config.ru CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # This file is used by Rack-based servers to start the application.
3
4
 
4
5
  require ::File.expand_path('../config/environment', __FILE__)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rails/generators/active_record'
3
4
 
4
5
  module Monarchy
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rails/generators/active_record'
3
4
 
4
5
  module Monarchy
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Monarchy
3
4
  module ActsAsHierarchy
4
5
  extend ActiveSupport::Concern
@@ -17,6 +18,14 @@ module Monarchy
17
18
 
18
19
  validates :resource_type, presence: true
19
20
  validates :resource_id, uniqueness: { scope: [:resource_type] }, presence: true
21
+
22
+ include Monarchy::ActsAsHierarchy::InstanceMethods
23
+ end
24
+ end
25
+
26
+ module InstanceMethods
27
+ def accessible_for(user, options = {})
28
+ self.class.accessible_for(user, options).find_by(id: id).present?
20
29
  end
21
30
  end
22
31
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Monarchy
3
4
  module ActsAsMember
4
5
  extend ActiveSupport::Concern
@@ -29,7 +30,7 @@ module Monarchy
29
30
 
30
31
  scope :with_access_to, (lambda do |resource|
31
32
  Monarchy::Validators.resource(resource)
32
- with_ancestors_access(resource).union(with_descendants_access(resource))
33
+ where(id: with_ancestors_access(resource).union(with_descendants_access(resource)))
33
34
  end)
34
35
  end
35
36
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Monarchy
3
4
  module ActsAsResource
4
5
  extend ActiveSupport::Concern
@@ -94,6 +95,10 @@ module Monarchy
94
95
  )
95
96
  end
96
97
 
98
+ def accessible_for(user)
99
+ hierarchy.accessible_for(user)
100
+ end
101
+
97
102
  private
98
103
 
99
104
  def assign_parent(force = false)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Monarchy
3
4
  module ActsAsRole
4
5
  extend ActiveSupport::Concern
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Monarchy
3
4
  module ActsAsUser
4
5
  extend ActiveSupport::Concern
@@ -23,7 +24,7 @@ module Monarchy
23
24
  end)
24
25
 
25
26
  scope :with_access_to, (lambda do |resource|
26
- User.where(id: Member.with_access_to(resource).select(:user_id))
27
+ where(id: Monarchy.member_class.with_access_to(resource).select(:user_id))
27
28
  end)
28
29
  end
29
30
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Monarchy
3
4
  class Engine < Rails::Engine
4
5
  isolate_namespace Monarchy
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Monarchy
3
4
  module Exceptions
4
5
  class Error < StandardError; end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'tqdm'
3
4
 
4
5
  module Monarchy
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Monarchy
3
4
  module Validators
4
5
  class << self
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Monarchy
3
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
4
5
  end
data/lib/monarchy.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'closure_tree'
3
4
  require 'configurations'
4
5
  require 'active_record_union'
data/monarchy.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  lib = File.expand_path('../lib', __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
  require 'monarchy/version'
@@ -9,7 +10,7 @@ Gem::Specification.new do |s|
9
10
  s.name = 'monarchy'
10
11
  s.version = Monarchy::VERSION
11
12
  s.authors = ['Exelord']
12
- s.email = ['']
13
+ s.email = ['exelord@macsour.com']
13
14
  s.homepage = 'https://github.com/Exelord/Monarchy'
14
15
  s.summary = 'Hierarchical access management system with roles inheritance.'
15
16
  s.description = s.summary
@@ -27,7 +28,7 @@ Gem::Specification.new do |s|
27
28
  s.required_ruby_version = '>= 2.3'
28
29
 
29
30
  s.add_dependency 'activerecord', '>=4.2.7.1'
30
- s.add_dependency 'closure_tree', '6.3.0'
31
+ s.add_dependency 'closure_tree', '6.5.0'
31
32
  s.add_dependency 'configurations', '2.2.2'
32
33
  s.add_dependency 'active_record_union', '1.2.0'
33
34
  s.add_dependency 'tqdm', '0.3.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monarchy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Exelord
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-30 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 6.3.0
33
+ version: 6.5.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 6.3.0
40
+ version: 6.5.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: configurations
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +124,7 @@ dependencies:
124
124
  version: 3.5.0
125
125
  description: Hierarchical access management system with roles inheritance.
126
126
  email:
127
- - ''
127
+ - exelord@macsour.com
128
128
  executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []