dynamican 0.1.9 → 0.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.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/dynamican.gemspec +1 -1
- data/lib/dynamican/evaluator.rb +2 -2
- data/lib/models/dynamican/permission_connector.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3229463775ada8d5f0a281fadf656089554b8f155ed282fab690134c918666bf
|
4
|
+
data.tar.gz: 74a027bece14bfa3555c70ca9baa54d265d7110184e6c43bab0d2a1e5bbfd911
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f903194f76b1a0324e175dc4c896827d35244ed43281ff2e148d3779bd3f3207948d57af6afe484dae703ab34bcaf04e7fdff1fc711f6a6398d9a0079bd3a8a
|
7
|
+
data.tar.gz: 6c06f2340a7807b90e1a50cf010a72ba1c4725387094502622aee686059e0bfb374bcff26ef756cf2b06484e66fc1382d3ac5f26890c97e0f54a28c4ac85b309
|
data/README.md
CHANGED
@@ -22,10 +22,14 @@ Create `config/dynamican.yml` file in your project and compile it as follows for
|
|
22
22
|
|
23
23
|
Once this config file is created, you can launch the following command.
|
24
24
|
|
25
|
-
rails
|
25
|
+
rails g dynamican_migration
|
26
26
|
|
27
27
|
This command will generate a migration file in your project. Inside this migration, the `permission_connectors` table will have a reference column for the models you configured in the config file. If you want to add the feature to a new model after your migrations are already run (and cannot be rollbacked) you need to create a new migration to add the corresponding columns in the `permission_connectors` table.
|
28
28
|
|
29
|
+
Now that you have your migration, just migrate.
|
30
|
+
|
31
|
+
rails db:migrate
|
32
|
+
|
29
33
|
### Using a model permissions on another model
|
30
34
|
|
31
35
|
I wanted to have the possibility to assign permissions both directly to my User model and my Role model, so that if the User had one permission and one of its Role had another, the User could benefit from both. So i assigned the feature (as explained above) to both models and then decorated my User model like following.
|
data/dynamican.gemspec
CHANGED
data/lib/dynamican/evaluator.rb
CHANGED
@@ -23,7 +23,7 @@ module Dynamican
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def set_instance_variables
|
26
|
-
instance_variable_set("@#{subject.
|
26
|
+
instance_variable_set("@#{subject.class.name.demodulize.underscore}", subject)
|
27
27
|
|
28
28
|
conditions_instances.each do |instance_name, instance_object|
|
29
29
|
instance_variable_set("@#{instance_name}", instance_object)
|
@@ -36,7 +36,7 @@ module Dynamican
|
|
36
36
|
elsif object.is_a?(NilClass)
|
37
37
|
nil
|
38
38
|
else
|
39
|
-
object.class.
|
39
|
+
object.class.name.demodulize.underscore
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Dynamican
|
2
2
|
class PermissionConnector < ActiveRecord::Base
|
3
3
|
Dynamican.configuration.associations.each do |association_name, association_options|
|
4
|
-
belongs_to association_name.to_sym, class_name: association_options[:class_name], inverse_of:
|
4
|
+
belongs_to association_name.to_sym, class_name: association_options[:class_name], inverse_of: :permission_connectors, foreign_key: "#{association_name}_id".to_sym, optional: true
|
5
5
|
end
|
6
6
|
has_and_belongs_to_many :conditions, class_name: 'Dynamican::Condition', inverse_of: :permission_connectors, foreign_key: :permission_connector_id
|
7
7
|
belongs_to :permission, class_name: 'Dynamican::Permission', inverse_of: :permission_connectors, foreign_key: :permission_id
|