rails-acu 1.2.1

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 (117) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.project +18 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +30 -0
  6. data/Gemfile +30 -0
  7. data/Gemfile.lock +169 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.md +221 -0
  10. data/Rakefile +26 -0
  11. data/bin/rails +13 -0
  12. data/lib/acu/configs.rb +30 -0
  13. data/lib/acu/engine.rb +9 -0
  14. data/lib/acu/errors.rb +37 -0
  15. data/lib/acu/helpers/helpers.rb +9 -0
  16. data/lib/acu/injectors.rb +15 -0
  17. data/lib/acu/listeners.rb +18 -0
  18. data/lib/acu/monitor.rb +201 -0
  19. data/lib/acu/rules.rb +134 -0
  20. data/lib/acu/utilities.rb +14 -0
  21. data/lib/acu/version.rb +3 -0
  22. data/lib/generators/acu/install_generator.rb +20 -0
  23. data/lib/generators/templates/rules.rb +34 -0
  24. data/lib/generators/templates/setup.rb +30 -0
  25. data/lib/rails-acu.rb +26 -0
  26. data/rails-acu-1.2.0.gem +0 -0
  27. data/rails-acu.gemspec +23 -0
  28. data/spec/dummy/Rakefile +6 -0
  29. data/spec/dummy/app/assets/config/manifest.js +5 -0
  30. data/spec/dummy/app/assets/javascripts/admin/manage.js +2 -0
  31. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  32. data/spec/dummy/app/assets/javascripts/books.js +2 -0
  33. data/spec/dummy/app/assets/javascripts/cable.js +12 -0
  34. data/spec/dummy/app/assets/javascripts/comments.js +2 -0
  35. data/spec/dummy/app/assets/javascripts/home.js +2 -0
  36. data/spec/dummy/app/assets/stylesheets/admin/manage.css +4 -0
  37. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  38. data/spec/dummy/app/assets/stylesheets/books.css +4 -0
  39. data/spec/dummy/app/assets/stylesheets/comments.css +4 -0
  40. data/spec/dummy/app/assets/stylesheets/home.css +4 -0
  41. data/spec/dummy/app/assets/stylesheets/scaffold.css +84 -0
  42. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  43. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  44. data/spec/dummy/app/controllers/admin/manage_controller.rb +19 -0
  45. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  46. data/spec/dummy/app/controllers/home_controller.rb +7 -0
  47. data/spec/dummy/app/helpers/admin/manage_helper.rb +2 -0
  48. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  49. data/spec/dummy/app/helpers/home_helper.rb +2 -0
  50. data/spec/dummy/app/jobs/application_job.rb +2 -0
  51. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  52. data/spec/dummy/app/models/application_record.rb +3 -0
  53. data/spec/dummy/app/models/user.rb +8 -0
  54. data/spec/dummy/app/models/user_type.rb +3 -0
  55. data/spec/dummy/app/views/admin/manage/add.html.erb +2 -0
  56. data/spec/dummy/app/views/admin/manage/delete.html.erb +2 -0
  57. data/spec/dummy/app/views/admin/manage/index.html.erb +2 -0
  58. data/spec/dummy/app/views/admin/manage/list.html.erb +2 -0
  59. data/spec/dummy/app/views/admin/manage/prove.html.erb +2 -0
  60. data/spec/dummy/app/views/admin/manage/show.html.erb +2 -0
  61. data/spec/dummy/app/views/home/contact.html.erb +2 -0
  62. data/spec/dummy/app/views/home/index.html.erb +21 -0
  63. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  64. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  65. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  66. data/spec/dummy/bin/bundle +3 -0
  67. data/spec/dummy/bin/rails +4 -0
  68. data/spec/dummy/bin/rake +4 -0
  69. data/spec/dummy/bin/setup +34 -0
  70. data/spec/dummy/bin/update +29 -0
  71. data/spec/dummy/config.ru +5 -0
  72. data/spec/dummy/config/application.rb +23 -0
  73. data/spec/dummy/config/boot.rb +5 -0
  74. data/spec/dummy/config/cable.yml +9 -0
  75. data/spec/dummy/config/database.yml +25 -0
  76. data/spec/dummy/config/environment.rb +5 -0
  77. data/spec/dummy/config/environments/development.rb +54 -0
  78. data/spec/dummy/config/environments/production.rb +86 -0
  79. data/spec/dummy/config/environments/test.rb +42 -0
  80. data/spec/dummy/config/initializers/acu_rules.rb +31 -0
  81. data/spec/dummy/config/initializers/acu_setup.rb +14 -0
  82. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  83. data/spec/dummy/config/initializers/assets.rb +11 -0
  84. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  85. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  86. data/spec/dummy/config/initializers/devise.rb +277 -0
  87. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  88. data/spec/dummy/config/initializers/inflections.rb +16 -0
  89. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  90. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  91. data/spec/dummy/config/initializers/session_store.rb +3 -0
  92. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  93. data/spec/dummy/config/locales/devise.en.yml +64 -0
  94. data/spec/dummy/config/locales/en.yml +23 -0
  95. data/spec/dummy/config/puma.rb +47 -0
  96. data/spec/dummy/config/routes.rb +19 -0
  97. data/spec/dummy/config/secrets.yml +22 -0
  98. data/spec/dummy/config/spring.rb +6 -0
  99. data/spec/dummy/db/migrate/20170329111257_create_books.rb +9 -0
  100. data/spec/dummy/db/migrate/20170329111323_create_comments.rb +10 -0
  101. data/spec/dummy/db/migrate/20170329114943_devise_create_users.rb +42 -0
  102. data/spec/dummy/db/migrate/20170329120950_create_admin_user_types.rb +15 -0
  103. data/spec/dummy/db/migrate/20170329121612_add_user_type_id_to_users.rb +5 -0
  104. data/spec/dummy/db/schema.rb +59 -0
  105. data/spec/dummy/db/seeds.rb +39 -0
  106. data/spec/dummy/public/404.html +67 -0
  107. data/spec/dummy/public/422.html +67 -0
  108. data/spec/dummy/public/500.html +66 -0
  109. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  110. data/spec/dummy/public/apple-touch-icon.png +0 -0
  111. data/spec/dummy/public/favicon.ico +0 -0
  112. data/spec/dummy/spec/controllers/admin/manage_controller_spec.rb +72 -0
  113. data/spec/dummy/spec/controllers/application_controller_spec.rb +14 -0
  114. data/spec/dummy/spec/controllers/home_controller_spec.rb +560 -0
  115. data/spec/rails_helper.rb +59 -0
  116. data/spec/spec_helper.rb +104 -0
  117. metadata +268 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5e4832b86ac7f688e4f9a710bc490471b33dc8e
4
+ data.tar.gz: fd9a65c185a13acf5e40b03037aedf246cc9229c
5
+ SHA512:
6
+ metadata.gz: 0a15a8d3858a25f9cc9e121b736632c8cc2d16f5ffd68ac107b4f66d3720242a69f076f6c48ded26f276ceb56e0d4f6cef16aed6d2706341dbe657d22e780457
7
+ data.tar.gz: 57d389156e2682b7ba1959842ba943f5dd2dcec89cb5b5679c4ca821cdcb8947b327196904d8bec72e69d862caa3d130bbf8e18aba51329e1c587644fb914d19
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/db/*.sqlite3-journal
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ *.byebug_history
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>acu</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.radrails.rails.core.railsnature</nature>
16
+ <nature>com.aptana.ruby.core.rubynature</nature>
17
+ </natures>
18
+ </projectDescription>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
@@ -0,0 +1,30 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.4.0
5
+
6
+ cache: bundler
7
+
8
+ sudo: false
9
+
10
+ env:
11
+ - RAILS_ENV=test
12
+
13
+ matrix:
14
+ fast_finish: true
15
+
16
+ before_install:
17
+ - gem update --system 2.6.11
18
+ - gem install bundler -v 1.14.6
19
+
20
+ script:
21
+ - export RAILS_ENV=test
22
+ - bundle exec rake db:create
23
+ - bundle exec rake db:migrate
24
+ - bundle exec rake db:seed
25
+ - bundle exec rspec
26
+
27
+ notifications:
28
+ email:
29
+ recipients:
30
+ - b.g.dariush@gmail.com
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
8
+ # Declare your gem's dependencies in acu.gemspec.
9
+ # Bundler will treat runtime dependencies like base dependencies, and
10
+ # development dependencies will be added by default to the :development group.
11
+ gemspec
12
+
13
+ # Declare any dependencies that are still in development here instead of in
14
+ # your gemspec. These might include edge Rails or gems from your path or
15
+ # Git. Remember to move these dependencies to your gemspec before releasing
16
+ # your gem to rubygems.org.
17
+
18
+ # To use a debugger
19
+ # gem 'byebug', group: [:development, :test]
20
+
21
+ group :development, :test do
22
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
23
+ gem 'byebug', platform: :mri
24
+ gem 'rspec-rails', '~> 3.5'
25
+ gem 'sqlite3'
26
+ gem 'awesome_print', github: 'awesome-print/awesome_print'
27
+ gem 'devise'
28
+ gem 'jquery-rails'
29
+ gem 'rails-controller-testing'
30
+ end
@@ -0,0 +1,169 @@
1
+ GIT
2
+ remote: https://github.com/awesome-print/awesome_print.git
3
+ revision: 551bb9cd306aee74e338c92316c8709ff71fb305
4
+ specs:
5
+ awesome_print (1.7.0)
6
+
7
+ PATH
8
+ remote: .
9
+ specs:
10
+ rails-acu (1.2.1)
11
+ rails (~> 5.0.0, >= 5.0.0)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ actioncable (5.0.2)
17
+ actionpack (= 5.0.2)
18
+ nio4r (>= 1.2, < 3.0)
19
+ websocket-driver (~> 0.6.1)
20
+ actionmailer (5.0.2)
21
+ actionpack (= 5.0.2)
22
+ actionview (= 5.0.2)
23
+ activejob (= 5.0.2)
24
+ mail (~> 2.5, >= 2.5.4)
25
+ rails-dom-testing (~> 2.0)
26
+ actionpack (5.0.2)
27
+ actionview (= 5.0.2)
28
+ activesupport (= 5.0.2)
29
+ rack (~> 2.0)
30
+ rack-test (~> 0.6.3)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
33
+ actionview (5.0.2)
34
+ activesupport (= 5.0.2)
35
+ builder (~> 3.1)
36
+ erubis (~> 2.7.0)
37
+ rails-dom-testing (~> 2.0)
38
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
39
+ activejob (5.0.2)
40
+ activesupport (= 5.0.2)
41
+ globalid (>= 0.3.6)
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
+ arel (~> 7.0)
48
+ activesupport (5.0.2)
49
+ concurrent-ruby (~> 1.0, >= 1.0.2)
50
+ i18n (~> 0.7)
51
+ minitest (~> 5.1)
52
+ tzinfo (~> 1.1)
53
+ arel (7.1.4)
54
+ bcrypt (3.1.11)
55
+ builder (3.2.3)
56
+ byebug (9.0.6)
57
+ concurrent-ruby (1.0.5)
58
+ devise (4.2.1)
59
+ bcrypt (~> 3.0)
60
+ orm_adapter (~> 0.1)
61
+ railties (>= 4.1.0, < 5.1)
62
+ responders
63
+ warden (~> 1.2.3)
64
+ diff-lcs (1.3)
65
+ erubis (2.7.0)
66
+ globalid (0.3.7)
67
+ activesupport (>= 4.1.0)
68
+ i18n (0.8.1)
69
+ jquery-rails (4.3.1)
70
+ rails-dom-testing (>= 1, < 3)
71
+ railties (>= 4.2.0)
72
+ thor (>= 0.14, < 2.0)
73
+ loofah (2.0.3)
74
+ nokogiri (>= 1.5.9)
75
+ mail (2.6.4)
76
+ mime-types (>= 1.16, < 4)
77
+ method_source (0.8.2)
78
+ mime-types (3.1)
79
+ mime-types-data (~> 3.2015)
80
+ mime-types-data (3.2016.0521)
81
+ mini_portile2 (2.1.0)
82
+ minitest (5.10.1)
83
+ nio4r (2.0.0)
84
+ nokogiri (1.7.1)
85
+ mini_portile2 (~> 2.1.0)
86
+ orm_adapter (0.5.0)
87
+ rack (2.0.1)
88
+ rack-test (0.6.3)
89
+ rack (>= 1.0)
90
+ rails (5.0.2)
91
+ actioncable (= 5.0.2)
92
+ actionmailer (= 5.0.2)
93
+ actionpack (= 5.0.2)
94
+ actionview (= 5.0.2)
95
+ activejob (= 5.0.2)
96
+ activemodel (= 5.0.2)
97
+ activerecord (= 5.0.2)
98
+ activesupport (= 5.0.2)
99
+ bundler (>= 1.3.0, < 2.0)
100
+ railties (= 5.0.2)
101
+ sprockets-rails (>= 2.0.0)
102
+ rails-controller-testing (1.0.1)
103
+ actionpack (~> 5.x)
104
+ actionview (~> 5.x)
105
+ activesupport (~> 5.x)
106
+ rails-dom-testing (2.0.2)
107
+ activesupport (>= 4.2.0, < 6.0)
108
+ nokogiri (~> 1.6)
109
+ rails-html-sanitizer (1.0.3)
110
+ loofah (~> 2.0)
111
+ railties (5.0.2)
112
+ actionpack (= 5.0.2)
113
+ activesupport (= 5.0.2)
114
+ method_source
115
+ rake (>= 0.8.7)
116
+ thor (>= 0.18.1, < 2.0)
117
+ rake (12.0.0)
118
+ responders (2.3.0)
119
+ railties (>= 4.2.0, < 5.1)
120
+ rspec-core (3.5.4)
121
+ rspec-support (~> 3.5.0)
122
+ rspec-expectations (3.5.0)
123
+ diff-lcs (>= 1.2.0, < 2.0)
124
+ rspec-support (~> 3.5.0)
125
+ rspec-mocks (3.5.0)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.5.0)
128
+ rspec-rails (3.5.2)
129
+ actionpack (>= 3.0)
130
+ activesupport (>= 3.0)
131
+ railties (>= 3.0)
132
+ rspec-core (~> 3.5.0)
133
+ rspec-expectations (~> 3.5.0)
134
+ rspec-mocks (~> 3.5.0)
135
+ rspec-support (~> 3.5.0)
136
+ rspec-support (3.5.0)
137
+ sprockets (3.7.1)
138
+ concurrent-ruby (~> 1.0)
139
+ rack (> 1, < 3)
140
+ sprockets-rails (3.2.0)
141
+ actionpack (>= 4.0)
142
+ activesupport (>= 4.0)
143
+ sprockets (>= 3.0.0)
144
+ sqlite3 (1.3.13)
145
+ thor (0.19.4)
146
+ thread_safe (0.3.6)
147
+ tzinfo (1.2.3)
148
+ thread_safe (~> 0.1)
149
+ warden (1.2.7)
150
+ rack (>= 1.0)
151
+ websocket-driver (0.6.5)
152
+ websocket-extensions (>= 0.1.0)
153
+ websocket-extensions (0.1.2)
154
+
155
+ PLATFORMS
156
+ ruby
157
+
158
+ DEPENDENCIES
159
+ awesome_print!
160
+ byebug
161
+ devise
162
+ jquery-rails
163
+ rails-acu!
164
+ rails-controller-testing
165
+ rspec-rails (~> 3.5)
166
+ sqlite3
167
+
168
+ BUNDLED WITH
169
+ 1.14.6
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Dariush Hasanpour
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,221 @@
1
+ [![Build Status](https://travis-ci.org/noise2/rails-acu.svg?branch=master)](https://travis-ci.org/noise2/rails-acu)
2
+
3
+ # ACU
4
+ ACU is the acronym for **A**ccess **C**ontrol **U**nit, and it's designed to give the 100% control over permissions on multiple levels of rails application's structure.
5
+ The software engineering of this gem tends to make it much faster and simple. All you have to do is to define the **entities** of your authentications (i.e `what is who?`)
6
+ and write the rules for them based on `allow`/`deny` binary logic, and everything else will be done automatically.
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rails-acu'
13
+ ```
14
+
15
+ And then execute:
16
+ ```bash
17
+ $ bundle
18
+ ```
19
+
20
+ Or install it yourself as:
21
+ ```bash
22
+ $ gem install rails-acu
23
+ ```
24
+
25
+ Then install it in you app using:
26
+
27
+ ```bash
28
+ rails generate acu:install
29
+ ```
30
+
31
+ ## Usage
32
+ After installation using `rails generate acu:install` two files will be created:
33
+
34
+ ```bash
35
+ create config/initializers/acu_setup.rb
36
+ create config/initializers/acu_rules.rb
37
+ ```
38
+ The file `acu_setup.rb` is the configuration of ACU gem, you can leave it alone and use the default configurations or customize it as desired,
39
+ we will talk about the configuration later.
40
+
41
+ The other hand the `acu_rules.rb` is where you put your access rules there, access rules are binary, _either an entity can access a resource or not_ -
42
+ in this gem, resource means any of `namespace`, `controller` and `action`. here as an example `acu_rules.rb` and we explain its components in the following:
43
+
44
+ ```ruby
45
+ # config/initializers/acu_rules.rb
46
+ Acu::Rules.define do
47
+ # anyone makes a request could be count as everyone!
48
+ whois :everyone { true }
49
+
50
+ whois :admin, args: [:user] { |c| c and c.user_type == :ADMIN.to_s }
51
+
52
+ whois :client, args: [:user] { |c| c and c.user_type == :CLIENT.to_s }
53
+
54
+ # the default namespace
55
+ namespace do
56
+ controller :home, except: [:some_secret_action] do
57
+ allow :everyone
58
+ end
59
+ controller :home do
60
+ allow [:admin, :client], on: [:some_secret_action]
61
+ end
62
+ end
63
+
64
+ # the admin namespace
65
+ namespace :admin do
66
+ allow :admin
67
+
68
+ controller :contact, only: [:send_message] do
69
+ allow :everyone
70
+ end
71
+
72
+ controller :contact do
73
+ action :support {
74
+ allow :client
75
+ }
76
+ end
77
+ end
78
+ end
79
+ ```
80
+
81
+ As we define our rules at the first line, we have to say who are the entities? _to whom we call who?_ for this purpose I have come up with a simple entity definition `whois`, it takes three arguments (1 of them is optional: `args`), first the label of the entity, in this example they are `:everyone, :admin` and `:client`, the second argument (which is optional) is the variables that are going to be used to determining if the current request has been initiated by the entity or not, and the final argument is a block which its job is to determine who is the defined entity!
82
+
83
+ Once we defined our entities we can set their binary access permissions at namespace/controller/action levels using `allow` and `deny` helpers. **that is it, we are done tutorialing; from now on is just tiny details. :)**
84
+
85
+ > **Scenario:** We have a *public* site which serves to its client's; we have 2 namespaces on this site, one is the _default_ namespace with _home_ controller in it, and the second namespace belongs to the _admin_ of site which has many controllers and also a _contact_ controller.<br />
86
+ We want to grant access to everyone for all of _home_ controller actions in _default_ namespace **except** the `some_secret_action`; but this `some_secret_action` can be accessed via the `:admin` and `:client` entities.<br />
87
+ By default only `:admin` can access to the _admin_ namespace, but we made an exception for 2 actions in the `Admin::ContactController` which everyone can `send_message` to the admin and only clients can ask for `support`.<br />
88
+ If you back trace it in the above example you can easily find this scenario in the rules, plain and simple.
89
+
90
+ ### Entities' arguments
91
+ Occasionally there is some situation that you need to pass the some argument in the entities to be able to determine the entity (i.e you cannot get it from `session`, `global variables/function` or directly from `database`) for such situations you can pass the arguments in one of the **base controller**'s `before_action`s as below:
92
+
93
+ ```ruby
94
+ class ApplicationController < ActionController::Base
95
+ protect_from_forgery with: :exception
96
+
97
+ before_action { Acu::Monitor.by user: some_way_to_fetch_it }
98
+ end
99
+ ```
100
+ The method `Acu::Monitor.by` accepts with a hashed list of agruments, please note that the keys should be identical to the entities' `args` argument.
101
+
102
+ ### Some handy helpers
103
+ Although you can define a binary allow/deny access rule in the `acu_rules.rb` file but there will be some gray area that neither you can allow _full access_ to the resource nor _no access_.<br />
104
+ for those situations you allow the entities to get access but limits their operations in the action/view/layout with the `acu_is?` and `acu_as` helpers, here is some usage example of them:
105
+
106
+ ```ruby
107
+ # return true if the entity `:admin`'s block in `whois :admin` return true, otherwise false
108
+ acu_is? :admin
109
+ # returns true if any of the given entity's block return true; if none of the was valid, returns false.
110
+ acu_is? [:admin, :client]
111
+
112
+ # executes the block if current user identified as an admin by `whois :admin`
113
+ acu_as :admin do
114
+ puts 'You are identified as an `admin`'
115
+ end
116
+ # executes the block if current user identified as either `:admin` or `:client`
117
+ acu_as [:admin, :client] do
118
+ puts 'You are either `admin` or `client`'
119
+ end
120
+ ```
121
+
122
+ ### Configurations
123
+ One of the files that `acu:install` command will generate is `acu_setup.rb` which contains the configuration for the gem, the default configurations are as following:
124
+
125
+ ```ruby
126
+ Acu.setup do |config|
127
+ # name it to the Base Application Controller that your project
128
+ # is going to use as a base of all of your controllers.
129
+ config.base_controller = :ApplicationController
130
+
131
+ # to tighten the security this is enabled by default
132
+ # i.e if it checked to be true, then if a request didn't match to any of rules, it will get passed through
133
+ # otherwise the requests which don't fit into any of rules, the request is denied by default
134
+ config.allow_by_default = false
135
+
136
+ # the audit log file, to log how the requests handles, good for production
137
+ # leave it black for nil to disable the logging
138
+ config.audit_log_file = ""
139
+
140
+ # cache the rules to make rule matching much faster
141
+ # it's not recommended to use it in developement/test evn.
142
+ config.use_cache = false
143
+
144
+ # the caching namespace
145
+ config.cache_namespace = 'acu'
146
+
147
+ # define the expiration of cached entries
148
+ config.cache_expires_in = nil
149
+
150
+ # the race condition ttl
151
+ config.cache_race_condition_ttl = nil
152
+
153
+ # more details about cache options:
154
+ # http://guides.rubyonrails.org/caching_with_rails.html
155
+ end
156
+ ```
157
+
158
+ Here are the details of the configurations:
159
+
160
+ | Name | Default | Description |
161
+ | ----- |-------| ------ |
162
+ | base_controller | `:ApplicationController` | In order that ACU gem to work it will attach some utilities to the base controller of all controllers, so if your base controller's name is something else change it. |
163
+ | allow_by_default | `false` | Set it `true` if you want to grant access to requests that doesn't fit to any rules you have defined (**Warning:** please be advised, setting it `true` may cause a security hole in your website if you don't cover the rules perfectly!). |
164
+ | audit_log_file | | The audit log file, useful for rules debugging! |
165
+ | use_cache | `false` | ACU can utilize the `Rails.cache` to make the rules matching much faster by caching them, but if caching is enabled and you change the please make user you have cleared the ACU caches by `Acu::Monitor.clear_cache`. |
166
+ | cache_* | 'acu' or `nil` | See rails [caching options](http://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-store) for details. |
167
+
168
+ ### API
169
+ Here are the list of APIs that didn't mentioned above:
170
+
171
+ | API | Arguments | Alias | Description |
172
+ | ----- | :-------: | :------: | ---- |
173
+ | `Acu::Configs.get` | `name` | N/A | Get the value of the `name`ed config |
174
+ | `Acu::Monitor.by` | `kwargs` | N/A | Set the arguments demaned by blocks in `whois` |
175
+ | `Acu::Monitor.clear_cache` | None | N/A | Clears the ACU's rule matching cache |
176
+ | `Acu::Monitor.clear_args` | None | N/A | Clears the argument set by `Acu::Monitor.by` |
177
+ | `Acu::Monitor.valid_for?` | `entity` | `acu_is?` | Check if the current request is come from the entity or not |
178
+ | `Acu::Monitor.gaurd` | None | N/A | Validates the current request, this is called automatically just before Rails start calling the _action_ |
179
+ | `Acu::Rules.define` | `&block` | N/A | Get a block of rules, **Note** that there could be mutliple `Acu::Rules.define` in your project, the rules will all merge together as a one, so you can have mutliple `acu_rule*.rb` file in your `config/initialize` and they will merge together |
180
+ | `Acu::Rules.reset` | None | N/A | Resets everything in the `Acu::Rules` |
181
+ | `Acu::Rule.lock` | None | N/A | Freezes the rules, you can set it at the _end of the last_ `acu_rule*.rb` file. |
182
+
183
+
184
+ ### Exceptions
185
+ Here are the list of exceptions defined in ACU gem:
186
+
187
+ ```ruby
188
+ class Acu::Errors::AccessDenied < StandardError
189
+
190
+ class Acu::Errors::UncheckedPermissions < StandardError
191
+
192
+ class Acu::Errors::InvalidSyntax < StandardError
193
+
194
+ class Acu::Errors::AmbiguousRule < StandardError
195
+
196
+ class Acu::Errors::InvalidData < StandardError
197
+
198
+ class Acu::Errors::MissingData < InvalidData
199
+
200
+ class Acu::Errors::MissingEntity < MissingData
201
+
202
+ class Acu::Errors::MissingUser < MissingData
203
+
204
+ class Acu::Errors::MissingAction < MissingData
205
+
206
+ class Acu::Errors::MissingController < MissingData
207
+
208
+ class Acu::Errors::MissingNamespace < MissingData
209
+ ```
210
+
211
+
212
+
213
+ ## Contributing
214
+ In order contributing to this project:
215
+ 1. Fork
216
+ 2. Make changes/upgrades/fixes etc
217
+ 3. Write a through tests
218
+ 4. Make a pull request to the `develop` branch
219
+
220
+ ## License
221
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).