monarchy 1.1.5 → 2.0.0.pre.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +26 -0
  3. data/.gitignore +6 -6
  4. data/.rubocop.yml +3 -3
  5. data/CHANGELOG.md +11 -0
  6. data/Gemfile +4 -3
  7. data/Gemfile.lock +54 -53
  8. data/README.md +1 -0
  9. data/app/models/monarchy/hierarchy.rb +0 -1
  10. data/docs/acts_as_hierarchy.md +45 -0
  11. data/docs/acts_as_resource.md +103 -0
  12. data/docs/acts_as_user.md +52 -0
  13. data/docs/configuration.md +54 -0
  14. data/docs/installation.md +30 -0
  15. data/docs/usage.md +22 -0
  16. data/dummy/.rspec +2 -0
  17. data/dummy/README.rdoc +28 -0
  18. data/dummy/Rakefile +7 -0
  19. data/dummy/app/assets/images/.keep +0 -0
  20. data/dummy/app/assets/javascripts/application.js +13 -0
  21. data/dummy/app/assets/stylesheets/application.css +15 -0
  22. data/dummy/app/controllers/application_controller.rb +6 -0
  23. data/dummy/app/controllers/concerns/.keep +0 -0
  24. data/dummy/app/helpers/application_helper.rb +3 -0
  25. data/dummy/app/mailers/.keep +0 -0
  26. data/dummy/app/models/.keep +0 -0
  27. data/dummy/app/models/concerns/.keep +0 -0
  28. data/dummy/app/models/member.rb +4 -0
  29. data/dummy/app/models/memo.rb +5 -0
  30. data/dummy/app/models/project.rb +12 -0
  31. data/dummy/app/models/resource.rb +4 -0
  32. data/dummy/app/models/role.rb +4 -0
  33. data/dummy/app/models/status.rb +5 -0
  34. data/dummy/app/models/task.rb +5 -0
  35. data/dummy/app/models/user.rb +4 -0
  36. data/dummy/app/views/layouts/application.html.erb +14 -0
  37. data/dummy/bin/bundle +4 -0
  38. data/dummy/bin/rails +5 -0
  39. data/dummy/bin/rake +5 -0
  40. data/dummy/bin/setup +30 -0
  41. data/dummy/config/application.rb +25 -0
  42. data/dummy/config/boot.rb +6 -0
  43. data/dummy/config/database.yml +10 -0
  44. data/dummy/config/environment.rb +6 -0
  45. data/dummy/config/environments/development.rb +42 -0
  46. data/dummy/config/environments/production.rb +80 -0
  47. data/dummy/config/environments/test.rb +43 -0
  48. data/dummy/config/initializers/assets.rb +12 -0
  49. data/dummy/config/initializers/backtrace_silencers.rb +8 -0
  50. data/dummy/config/initializers/cookies_serializer.rb +4 -0
  51. data/dummy/config/initializers/filter_parameter_logging.rb +5 -0
  52. data/dummy/config/initializers/inflections.rb +17 -0
  53. data/dummy/config/initializers/mime_types.rb +5 -0
  54. data/dummy/config/initializers/monarchy.rb +46 -0
  55. data/dummy/config/initializers/session_store.rb +4 -0
  56. data/dummy/config/initializers/wrap_parameters.rb +15 -0
  57. data/dummy/config/locales/en.yml +23 -0
  58. data/dummy/config/routes.rb +57 -0
  59. data/dummy/config/secrets.yml +22 -0
  60. data/dummy/config.ru +5 -0
  61. data/dummy/db/migrate/20160220215254_monarchy_create_users.rb +7 -0
  62. data/dummy/db/migrate/20160221132205_monarchy_create_hierarchies.rb +22 -0
  63. data/dummy/db/migrate/20160221133215_monarchy_create_memberships.rb +38 -0
  64. data/dummy/db/migrate/20160221142305_create_memo_resource.rb +8 -0
  65. data/dummy/db/migrate/20160221142309_create_project_resource.rb +8 -0
  66. data/dummy/db/migrate/20160221154113_create_resource_resource.rb +8 -0
  67. data/dummy/db/migrate/20160306124820_add_memo_to_resource.rb +6 -0
  68. data/dummy/db/migrate/20160502212213_parent_as_setup.rb +7 -0
  69. data/dummy/db/migrate/20160815163909_task_model.rb +10 -0
  70. data/dummy/db/migrate/20160818205534_status.rb +9 -0
  71. data/dummy/db/schema.rb +111 -0
  72. data/dummy/lib/assets/.keep +0 -0
  73. data/dummy/public/404.html +67 -0
  74. data/dummy/public/422.html +67 -0
  75. data/dummy/public/500.html +66 -0
  76. data/dummy/public/favicon.ico +0 -0
  77. data/dummy/spec +1 -0
  78. data/lib/generators/templates/config.rb +44 -7
  79. data/lib/monarchy/acts_as_hierarchy.rb +12 -11
  80. data/lib/monarchy/acts_as_member.rb +8 -17
  81. data/lib/monarchy/acts_as_resource.rb +35 -22
  82. data/lib/monarchy/acts_as_user.rb +51 -39
  83. data/lib/monarchy/exceptions.rb +135 -0
  84. data/lib/monarchy/tasks.rb +1 -1
  85. data/lib/monarchy/validators.rb +83 -0
  86. data/lib/monarchy/version.rb +1 -1
  87. data/lib/monarchy.rb +21 -8
  88. data/monarchy.gemspec +4 -4
  89. metadata +85 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae3074e01b50dd43b63d376ebb3f2410a9e6f588
4
- data.tar.gz: c37f5e0d3bb7dd2998bbab3b0624c989e3027b38
3
+ metadata.gz: 9c68ab46ff143acf0dbf4724039a5eda03caad6a
4
+ data.tar.gz: 7bffa186ec4eddd5c42e08d9217197329f223c77
5
5
  SHA512:
6
- metadata.gz: ba65132a3f0e45e64ceec663be0a0c030013aea2d3c66e8bf5495b908a9e79f8bf04509b0a5a4163728db1828007e707be5cfc1e69de3e946df1ee270bad6cf8
7
- data.tar.gz: 9139f0b7de797402b124f2eb31fdb213bd72c317ebe30ef90bedbb4c755297424f7f30bcadf56b243279200b1b09d9958f44c78b9ef2b33c7f983d5c564471a5
6
+ metadata.gz: 2e2f56e8b44dc277700951c9fda570907ea47b1ba98e6050d3e2a256f2f42b5620b8e158087292f1c797255f0fda311fa2f43ccabf3eacb63ec635d9349e4dba
7
+ data.tar.gz: 406793fd9ad57d2c65872594840a7761c5592801ab536cd006b9fde3936b914177b61e78c1809c09fc9e12cb6f2d9ec80bf9d12de11ece9b92ba3a644f349f90
data/.codeclimate.yml ADDED
@@ -0,0 +1,26 @@
1
+ ---
2
+ engines:
3
+ brakeman:
4
+ enabled: true
5
+ bundler-audit:
6
+ enabled: true
7
+ duplication:
8
+ enabled: true
9
+ config:
10
+ languages:
11
+ - ruby
12
+ checks:
13
+ Similar code:
14
+ enabled: false
15
+ fixme:
16
+ enabled: true
17
+ rubocop:
18
+ enabled: true
19
+ ratings:
20
+ paths:
21
+ - Gemfile.lock
22
+ - "**.rb"
23
+ exclude_paths:
24
+ - spec/
25
+ - dummy/
26
+ - docs/
data/.gitignore CHANGED
@@ -1,12 +1,12 @@
1
1
  .bundle/
2
2
  log/*.log
3
3
  pkg/
4
- spec/dummy/log/*.log
5
- spec/dummy/db/*.sqlite3
6
- spec/dummy/db/*.sqlite3-journal
7
- spec/dummy/log/*.log
8
- spec/dummy/tmp/
9
- spec/dummy/.sass-cache
4
+ dummy/log/*.log
5
+ dummy/db/*.sqlite3
6
+ dummy/db/*.sqlite3-journal
7
+ dummy/log/*.log
8
+ dummy/tmp/
9
+ dummy/.sass-cache
10
10
  .DS_Store
11
11
  coverage/
12
12
  .lock-*
data/.rubocop.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.3
3
3
  Exclude:
4
- - 'spec/dummy/db/seeds.rb'
5
- - 'spec/dummy/db/migrate/**'
6
- - 'spec/dummy/db/schema.rb'
4
+ - 'dummy/db/seeds.rb'
5
+ - 'dummy/db/migrate/**'
6
+ - 'dummy/db/schema.rb'
7
7
  - 'lib/generators/templates/**/*'
8
8
  Documentation:
9
9
  Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ### 2.0.x LTS
2
+ - Docs in files
3
+ - Improve `.in` scope in AAR
4
+ - Change `.in` scope in AAH
5
+ - Now it takes `hierarchy` and returns array of `hierarchies`
6
+ - Update gems
7
+ - Add dynamic `hierarchy` class
8
+ - Add `users` relationship to AAH
9
+ - Add a validator for `hierarchy`
10
+ - Add new exceptions for `hierarchy`
11
+ - Fix scopes in `hierarchy`
data/Gemfile CHANGED
@@ -16,11 +16,11 @@ gemspec
16
16
  # gem 'byebug', group: [:development, :test]
17
17
 
18
18
  group :development, :test do
19
- gem 'sqlite3', '1.3.11'
20
- gem 'rubocop', '0.42.0'
19
+ gem 'sqlite3', '1.3.12'
20
+ gem 'rubocop', '0.43.0'
21
21
  gem 'pry-rails', '0.3.4'
22
22
  gem 'shoulda-matchers', '3.1.1'
23
- gem 'rspec-rails', '3.5.1'
23
+ gem 'rspec-rails', '3.5.2'
24
24
  gem 'factory_girl_rails', '4.7.0'
25
25
  gem 'ffaker', '2.2.0'
26
26
  gem 'database_cleaner', '1.5.3'
@@ -28,3 +28,4 @@ group :development, :test do
28
28
  end
29
29
 
30
30
  gem 'simplecov', '0.12.0', require: false, group: :test
31
+ gem 'codeclimate-test-reporter', group: :test, require: nil
data/Gemfile.lock CHANGED
@@ -1,48 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monarchy (1.1.5)
4
+ monarchy (2.0.0.pre.beta.1)
5
5
  active_record_union (= 1.2.0)
6
- closure_tree (= 6.1.0)
7
- configurations (= 2.2.0)
8
- rails (~> 4.2, >= 4.2.4)
6
+ closure_tree (= 6.2.0)
7
+ configurations (= 2.2.1)
8
+ rails (~> 4.2, >= 4.2.7.1)
9
9
  tqdm (= 0.3.0)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- actionmailer (4.2.7)
15
- actionpack (= 4.2.7)
16
- actionview (= 4.2.7)
17
- activejob (= 4.2.7)
14
+ actionmailer (4.2.7.1)
15
+ actionpack (= 4.2.7.1)
16
+ actionview (= 4.2.7.1)
17
+ activejob (= 4.2.7.1)
18
18
  mail (~> 2.5, >= 2.5.4)
19
19
  rails-dom-testing (~> 1.0, >= 1.0.5)
20
- actionpack (4.2.7)
21
- actionview (= 4.2.7)
22
- activesupport (= 4.2.7)
20
+ actionpack (4.2.7.1)
21
+ actionview (= 4.2.7.1)
22
+ activesupport (= 4.2.7.1)
23
23
  rack (~> 1.6)
24
24
  rack-test (~> 0.6.2)
25
25
  rails-dom-testing (~> 1.0, >= 1.0.5)
26
26
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
- actionview (4.2.7)
28
- activesupport (= 4.2.7)
27
+ actionview (4.2.7.1)
28
+ activesupport (= 4.2.7.1)
29
29
  builder (~> 3.1)
30
30
  erubis (~> 2.7.0)
31
31
  rails-dom-testing (~> 1.0, >= 1.0.5)
32
32
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
33
33
  active_record_union (1.2.0)
34
34
  activerecord (>= 4.0)
35
- activejob (4.2.7)
36
- activesupport (= 4.2.7)
35
+ activejob (4.2.7.1)
36
+ activesupport (= 4.2.7.1)
37
37
  globalid (>= 0.3.0)
38
- activemodel (4.2.7)
39
- activesupport (= 4.2.7)
38
+ activemodel (4.2.7.1)
39
+ activesupport (= 4.2.7.1)
40
40
  builder (~> 3.1)
41
- activerecord (4.2.7)
42
- activemodel (= 4.2.7)
43
- activesupport (= 4.2.7)
41
+ activerecord (4.2.7.1)
42
+ activemodel (= 4.2.7.1)
43
+ activesupport (= 4.2.7.1)
44
44
  arel (~> 6.0)
45
- activesupport (4.2.7)
45
+ activesupport (4.2.7.1)
46
46
  i18n (~> 0.7)
47
47
  json (~> 1.7, >= 1.7.7)
48
48
  minitest (~> 5.1)
@@ -51,12 +51,14 @@ GEM
51
51
  arel (6.0.3)
52
52
  ast (2.3.0)
53
53
  builder (3.2.2)
54
- closure_tree (6.1.0)
54
+ closure_tree (6.2.0)
55
55
  activerecord (>= 4.1.0)
56
56
  with_advisory_lock (>= 3.0.0)
57
+ codeclimate-test-reporter (0.6.0)
58
+ simplecov (>= 0.7.1, < 1.0.0)
57
59
  coderay (1.1.1)
58
60
  concurrent-ruby (1.0.2)
59
- configurations (2.2.0)
61
+ configurations (2.2.1)
60
62
  database_cleaner (1.5.3)
61
63
  diff-lcs (1.2.5)
62
64
  docile (1.1.5)
@@ -80,13 +82,11 @@ GEM
80
82
  mime-types-data (~> 3.2015)
81
83
  mime-types-data (3.2016.0521)
82
84
  mini_portile2 (2.1.0)
83
- minitest (5.9.0)
84
- nokogiri (1.6.8)
85
+ minitest (5.9.1)
86
+ nokogiri (1.6.8.1)
85
87
  mini_portile2 (~> 2.1.0)
86
- pkg-config (~> 1.1.7)
87
- parser (2.3.1.2)
88
+ parser (2.3.1.4)
88
89
  ast (~> 2.2)
89
- pkg-config (1.1.7)
90
90
  powerpack (0.1.1)
91
91
  pry (0.10.4)
92
92
  coderay (~> 1.1.0)
@@ -97,16 +97,16 @@ GEM
97
97
  rack (1.6.4)
98
98
  rack-test (0.6.3)
99
99
  rack (>= 1.0)
100
- rails (4.2.7)
101
- actionmailer (= 4.2.7)
102
- actionpack (= 4.2.7)
103
- actionview (= 4.2.7)
104
- activejob (= 4.2.7)
105
- activemodel (= 4.2.7)
106
- activerecord (= 4.2.7)
107
- activesupport (= 4.2.7)
100
+ rails (4.2.7.1)
101
+ actionmailer (= 4.2.7.1)
102
+ actionpack (= 4.2.7.1)
103
+ actionview (= 4.2.7.1)
104
+ activejob (= 4.2.7.1)
105
+ activemodel (= 4.2.7.1)
106
+ activerecord (= 4.2.7.1)
107
+ activesupport (= 4.2.7.1)
108
108
  bundler (>= 1.3.0, < 2.0)
109
- railties (= 4.2.7)
109
+ railties (= 4.2.7.1)
110
110
  sprockets-rails
111
111
  rails-deprecated_sanitizer (1.0.3)
112
112
  activesupport (>= 4.2.0.alpha)
@@ -116,18 +116,18 @@ GEM
116
116
  rails-deprecated_sanitizer (>= 1.0.1)
117
117
  rails-html-sanitizer (1.0.3)
118
118
  loofah (~> 2.0)
119
- railties (4.2.7)
120
- actionpack (= 4.2.7)
121
- activesupport (= 4.2.7)
119
+ railties (4.2.7.1)
120
+ actionpack (= 4.2.7.1)
121
+ activesupport (= 4.2.7.1)
122
122
  rake (>= 0.8.7)
123
123
  thor (>= 0.18.1, < 2.0)
124
124
  rainbow (2.1.0)
125
- rake (11.2.2)
125
+ rake (11.3.0)
126
126
  rspec (3.5.0)
127
127
  rspec-core (~> 3.5.0)
128
128
  rspec-expectations (~> 3.5.0)
129
129
  rspec-mocks (~> 3.5.0)
130
- rspec-core (3.5.2)
130
+ rspec-core (3.5.4)
131
131
  rspec-support (~> 3.5.0)
132
132
  rspec-expectations (3.5.0)
133
133
  diff-lcs (>= 1.2.0, < 2.0)
@@ -135,7 +135,7 @@ GEM
135
135
  rspec-mocks (3.5.0)
136
136
  diff-lcs (>= 1.2.0, < 2.0)
137
137
  rspec-support (~> 3.5.0)
138
- rspec-rails (3.5.1)
138
+ rspec-rails (3.5.2)
139
139
  actionpack (>= 3.0)
140
140
  activesupport (>= 3.0)
141
141
  railties (>= 3.0)
@@ -144,7 +144,7 @@ GEM
144
144
  rspec-mocks (~> 3.5.0)
145
145
  rspec-support (~> 3.5.0)
146
146
  rspec-support (3.5.0)
147
- rubocop (0.42.0)
147
+ rubocop (0.43.0)
148
148
  parser (>= 2.3.1.1, < 3.0)
149
149
  powerpack (~> 0.1)
150
150
  rainbow (>= 1.99.1, < 3.0)
@@ -162,17 +162,17 @@ GEM
162
162
  sprockets (3.7.0)
163
163
  concurrent-ruby (~> 1.0)
164
164
  rack (> 1, < 3)
165
- sprockets-rails (3.1.1)
165
+ sprockets-rails (3.2.0)
166
166
  actionpack (>= 4.0)
167
167
  activesupport (>= 4.0)
168
168
  sprockets (>= 3.0.0)
169
- sqlite3 (1.3.11)
169
+ sqlite3 (1.3.12)
170
170
  thor (0.19.1)
171
171
  thread_safe (0.3.5)
172
172
  tqdm (0.3.0)
173
173
  tzinfo (1.2.2)
174
174
  thread_safe (~> 0.1)
175
- unicode-display_width (1.1.0)
175
+ unicode-display_width (1.1.1)
176
176
  with_advisory_lock (3.0.0)
177
177
  activerecord (>= 3.2)
178
178
  thread_safe
@@ -182,22 +182,23 @@ PLATFORMS
182
182
 
183
183
  DEPENDENCIES
184
184
  bundler (~> 1.12)
185
+ codeclimate-test-reporter
185
186
  database_cleaner (= 1.5.3)
186
187
  factory_girl_rails (= 4.7.0)
187
188
  ffaker (= 2.2.0)
188
189
  monarchy!
189
190
  pry-rails (= 0.3.4)
190
- rake (~> 11.1)
191
+ rake (~> 11.3)
191
192
  rspec (= 3.5.0)
192
- rspec-rails (= 3.5.1)
193
- rubocop (= 0.42.0)
193
+ rspec-rails (= 3.5.2)
194
+ rubocop (= 0.43.0)
194
195
  shoulda-matchers (= 3.1.1)
195
196
  simplecov (= 0.12.0)
196
- sqlite3 (= 1.3.11)
197
+ sqlite3 (= 1.3.12)
197
198
  tqdm (= 0.3.0)
198
199
 
199
200
  RUBY VERSION
200
- ruby 2.3.0p0
201
+ ruby 2.3.1p112
201
202
 
202
203
  BUNDLED WITH
203
- 1.12.5
204
+ 1.13.6
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  [![Build Status](https://travis-ci.org/Exelord/Monarchy.svg?branch=master)](https://travis-ci.org/Exelord/Monarchy)
2
2
  [![Dependency Status](https://gemnasium.com/badges/github.com/Exelord/Monarchy.svg)](https://gemnasium.com/github.com/Exelord/Monarchy)
3
3
  [![Gitter](https://badges.gitter.im/Exelord/Monarchy.svg)](https://gitter.im/Exelord/Monarchy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
4
+ [![Code Climate](https://codeclimate.com/github/Exelord/Monarchy/badges/gpa.svg)](https://codeclimate.com/github/Exelord/Monarchy)
4
5
 
5
6
  <p align="center">
6
7
  <img align="center" src="monarchy.png?raw=true" alt="Sublime's custom image"/>
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Monarchy::Hierarchy < ActiveRecord::Base
3
- self.table_name = 'monarchy_hierarchies'
4
3
  acts_as_hierarchy
5
4
  end
@@ -0,0 +1,45 @@
1
+ ## Hierarchy
2
+ `Hierarchy` is an internal model of `Monarchy` and should not be used unless it is really necessary.
3
+
4
+ > hmm... sounds like `private`
5
+
6
+ ### Methods
7
+ ** We do not recommend to use it but if yo have to: **
8
+ 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
+
10
+ [e5c808aa]: https://github.com/mceachen/closure_tree "Closure Tree"
11
+
12
+ ### Scopes:
13
+
14
+ #### .accessible_for
15
+ You can select all hierarchies accessible for specific user by using a scope: `accessible_for`, eg:
16
+ ``` ruby
17
+ Monarchy::Hierarchy.accessible_for(current_user) # returns [hierarchy1, hierarchy2, hierarchy5]
18
+ ```
19
+
20
+ #### .in(resource, true)
21
+ You can select all hierarchies scoped into another by using scope: `in`:
22
+
23
+ - If the second argument is `true` (`true` is by default):
24
+ ``` ruby
25
+ Monarchy::Hierarchy.in(project.hierarchy) # returns [hierarchy1, hierarchy2, hierarchy5]
26
+ ```
27
+ It will returns for you all `hierarchies` which parent is `project.hierarchy` or one of his children.
28
+
29
+ - If the second argument is `false`:
30
+ ``` ruby
31
+ Monarchy::Hierarchy.in(project.hierarchy, false) # returns [hierarchy1, hierarchy2]
32
+ ```
33
+ It will returns for you all `hierarchies` which parent is `project.hierarchy`
34
+
35
+
36
+ ## Relations
37
+
38
+ #### #members
39
+ Return all members explicitly granted to the hierarchy.
40
+
41
+ #### #users
42
+ Returns all users which have been granted explicitly to the hierarchy.
43
+
44
+ #### #resource
45
+ Returns a resource model of the hierarchy.
@@ -0,0 +1,103 @@
1
+ To generate a new resource you can use:
2
+ ```
3
+ rails g monarchy:resource [resource_name]
4
+ ```
5
+ or add to an existing model `acts_as_resource`, eg:
6
+ ```ruby
7
+ class Resource < ActiveRecord::Base
8
+ acts_as_resource
9
+ end
10
+ ```
11
+
12
+ ##### - Options
13
+ You can pass an options to `acts_as_resource`:
14
+ - `parent_as: :association_name`
15
+
16
+ This let you directly assign parent when you assign an association,
17
+ eg:
18
+ ``` ruby
19
+ class Task << ActiveRecord::Base
20
+ acts_as_resource parent_as: :project
21
+ belongs_to :project
22
+ end
23
+
24
+ task.update(project: Project.last)
25
+ task.parent # returns Project.last
26
+ ```
27
+
28
+ ## Methods
29
+
30
+ #### #parent
31
+ You can easily assign parent by using `parent=` method, eg:
32
+ ``` ruby
33
+ resource.parent = Project.last
34
+ ```
35
+ and read value by using `parent` method:
36
+ ``` ruby
37
+ resource.parent # returns Project.last
38
+ ```
39
+
40
+ Parents can be only models which have `acts_as_resource`
41
+
42
+ #### #children
43
+ You can easily assign children by using `children=` method, eg:
44
+ ``` ruby
45
+ resource.children = [child1, child2, child3]
46
+ ```
47
+ and read value by using `parent` method:
48
+ ``` ruby
49
+ resource.children # returns [child1, child2, child3]
50
+ ```
51
+ Children can be only models which have `acts_as_resource`
52
+
53
+ #### #ensure_hierarchy
54
+ It creates a hierarchy for resource model if it not exist and `automatic_hierarchy` flag is set to true.
55
+ If you want to bypass `automatic_hierarchy` flag you can pass `true` to the method params.
56
+
57
+ #### .default_role_name
58
+ Returns default role name for the class
59
+
60
+ #### .default_role
61
+ Returns default role object `Monarchy::Role` for the class
62
+
63
+ ### Scopes:
64
+
65
+ #### .accessible_for
66
+ You can select all resources accessible for specyfic user by using scope: `accessible_for`, eg:
67
+ ``` ruby
68
+ Resource.accessible_for(current_user) # returns [resource1, resource2, resource5]
69
+ ```
70
+
71
+ #### .in(resource, true)
72
+ You can select all resources scoped into another by using scope: `in`:
73
+
74
+ - If the second argument is `true` (`true` is by default):
75
+ ``` ruby
76
+ Resource.in(Project.first) # returns [resource1, resource5, resource6]
77
+ ```
78
+ It will return for you all `resources` which parent is `Project.first` or one of his children.
79
+
80
+ - If the second argument is `false`:
81
+ ``` ruby
82
+ Resource.in(Project.first, false) # returns [resource1, resource5]
83
+ ```
84
+ It will return for you all `resources` which parent is `Project.first`
85
+
86
+
87
+ ## Relations
88
+
89
+ #### #members
90
+ Return all members explicitly granted to the resource.
91
+
92
+ #### #users
93
+ Returns all users which have been granted explicitly to the resource.
94
+
95
+ #### #hierarchy
96
+ Returns a hierarchy model of the resource. (DO NOT USE UNLESS IS NECESSARY)
97
+
98
+ ## Flags
99
+ Every class which is actually the resource (`acts_as_resource`) has available flags.
100
+ ### .acting_as_resource
101
+ If a model class has `acts_as_resource` it returns `true` otherwise method is undefined.
102
+ ### .parentize_name
103
+ If a model class has `acts_as_resource` it returns class name of the parent if has been set by 'parent_as' option.
@@ -0,0 +1,52 @@
1
+ You have to add it to your user model or the custom one specified in a config file.
2
+
3
+ ``` ruby
4
+ class User < ActiveRecord::Base
5
+ acts_as_user
6
+ end
7
+ ```
8
+
9
+ ## Relations
10
+
11
+ #### .hierarchies
12
+ Return all hierarchies in which user is explicitly granted.
13
+
14
+ #### .members
15
+ Returns all memberships (`member` model) of the user
16
+
17
+ ## Scopes
18
+
19
+ #### .accessible_for (user)
20
+ Returns all users accessible for the specific user
21
+ It includes all users from all resource which the user has any access.
22
+
23
+ ## Methods
24
+
25
+ #### #roles_for(resource, inheritance = true)
26
+ Returns all roles for the user to the specific `resource`.
27
+ You can choose if this method should return also inherited roles or just these, granted explicitly.
28
+
29
+ #### #member_for(resource)
30
+ Returns a `member` object for the user in specyfic resource.
31
+
32
+ #### #grant(role_names, resource)
33
+ By this method, you can give the user an access to a specific resource.
34
+ You can specify a role name or an array of roles names.
35
+ **Remember to use `symbols`!**
36
+
37
+ #### #revoke_access(resource)
38
+ You can revoke total access of a user from the resource and his children by using this method.
39
+ Optionally you can specify `hierarchies` as the second argument from which user's members should be deleted.
40
+
41
+ #### #revoke_role(role_name, resource)
42
+ It revokes specified role from a user's member of the resource.
43
+ If is it last role and the default for the resource it will raise an error `Monarchy::Exceptions::RoleNotRevokable`. Otherwise, if it's just a last role it will remove the one and grant a user with default one.
44
+
45
+ **It guaranty that user will have always last role or a default one**
46
+
47
+ #### #revoke_role!(role_name, resource)
48
+ It behaves exactly like `#revoke_role` but with one difference during revoking last_role.
49
+ Depend on which `revoke_strategy` did you choose in configuration,
50
+ it will delete a member after revoking the last role or will revoke an access to the resource.
51
+
52
+ For more information check the [configuration page](https://github.com/Exelord/Monarchy/wiki/Configuration) and `revoke_strategy` property.
@@ -0,0 +1,54 @@
1
+ # Configuration file
2
+
3
+ You can configure Monarchy in `config/initializers/monarchy.rb` file. All available configuration options are already there and waiting for your orders.
4
+
5
+ ``` ruby
6
+ Monarchy.configure do |config|
7
+ # REQUIRED SETTINGS
8
+
9
+ # You have to define which role will be the default one (read only) during inheritance.
10
+ # Example role: :guest
11
+ # Real case on resources:
12
+ # project: (you have no roles)
13
+ # section: (you have no roles)
14
+ # task: (you have a member role here)
15
+ # When you ask for user.roles_for(project) you will get a default role (:guest)
16
+ # in case when member role has inherited flag set to true
17
+ # Remember to create that role before setting it up eg:
18
+ # Monarchy::Role.create(name: :guest, inherited: false, level: 0)
19
+ config.inherited_default_role = nil # symbol
20
+
21
+ # You have to define user class name or an actor class which respond to acts_as_user in your model.
22
+ # Example of model:
23
+ # class User < ActiveRecord::Base
24
+ # acts_as_user
25
+ # end
26
+ config.user_class_name = '' # string
27
+
28
+
29
+ # OPTIONAL SETTINGS
30
+
31
+ # If you want to override Member or Role class you have add correct actors to class definition
32
+ # Available: acts_as_member, acts_as_role, acts_as_hierarchy
33
+ # Example:
34
+ # class Member < ActiveRecord::Base
35
+ # acts_as_member
36
+ # end
37
+ config.role_class_name = 'Monarchy::Role' # string
38
+ config.member_class_name = 'Monarchy::Member' # string
39
+ config.hierarchy_class_name = 'Monarchy::Hierarchy' # string
40
+
41
+
42
+ # If this option is setup to true all members bellow the destroying one, will be deleted.
43
+ config.members_access_revoke = false # boolean
44
+
45
+ # Set the revoke strategy using during '#revoke_role!' method
46
+ # Available: :revoke_member, :revoke_access
47
+ # Default: :revoke_member
48
+ # Info:
49
+ # :revoke_member - after revoking the last role from user's member remove the member
50
+ # :revoke_access - after revoking the last role from user's member
51
+ # remove the member, and all members bellow which belongs to the user
52
+ config.revoke_strategy = :revoke_member # symbol
53
+ end
54
+ ```
@@ -0,0 +1,30 @@
1
+ # Installation
2
+ Add this line to your application's Gemfile:
3
+
4
+ ```ruby
5
+ gem 'monarchy'
6
+ ```
7
+
8
+ And then execute:
9
+
10
+ $ bundle
11
+
12
+ To create initials migrations and necessary files run:
13
+ ```
14
+ rails g monarchy:setup
15
+ ```
16
+
17
+ This will create for you:
18
+
19
+ 1. Migrations:
20
+ - `monarchy_create_users`
21
+ - `monarchy_create_hierarchies`
22
+ - `monarchy_create_memberships`
23
+ 2. Configuration file in `config/initializers/monarchy`
24
+ 3. Default `User` model (optional)
25
+
26
+ **If you want to use your current `User` model just skip generation of: **
27
+ - `db/migrate/monarchy_create_users.rb`
28
+ - `app/models/user.rb`
29
+
30
+ And add to your current `User` model `acts_as_user`
data/docs/usage.md ADDED
@@ -0,0 +1,22 @@
1
+ # Usage
2
+ The only think you have to do is mark models to be one of part of Monarchy.
3
+
4
+ You can use 2 available markers:
5
+
6
+ 1. `acts_as_user`
7
+ 2. `acts_as_resource`
8
+
9
+ ## Acts as user
10
+ For your current `User` model or freshly generated one, add or check if exist, `acts_as_user`.
11
+ ``` ruby
12
+ class User < ActiveRecord::Base
13
+ acts_as_user
14
+ end
15
+ ```
16
+
17
+ > Check documentation of [Acts as user] (https://github.com/Exelord/Monarchy/wiki/Acts-as-user)
18
+
19
+ ## Acts as resource
20
+ For all models that you want to be accessible for users add `acts_as_resource`.
21
+
22
+ > Check documentation of [Acts as resource] (https://github.com/Exelord/Monarchy/wiki/Acts-as-resource)
data/dummy/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/dummy/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.