fencepost 0.1.1 → 0.1.2
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/lib/fencepost.rb +10 -1
- data/lib/fencepost/configuration.rb +9 -0
- data/lib/fencepost/fencepost.rb +9 -1
- data/lib/fencepost/gate.rb +9 -2
- data/lib/fencepost/version.rb +1 -1
- data/lib/generators/fencepost_config_generator.rb +10 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f017e22be8ba3a0e67b270a401d2fb331cf33ebc
|
4
|
+
data.tar.gz: 409354913b4fbbc7b0c99533b0a068e6ae81423b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77243556c1c6483cfb0450744b7d97e0a7bfc136701c790519e7307b0fb67baeae6b39b772987385c4f1b8fa8ecf799ee221e311ef90143b844005aa77b6d1a5
|
7
|
+
data.tar.gz: a74cefd558f5e6c83b1dfa28f285dd25963d99ced1dd9947ab93f838e51922290da7b96aed213a3e8d3139e0f9b24bf7e293ed0122bb326870571e20238fd8f4
|
data/lib/fencepost.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
require "fencepost/fencepost"
|
2
|
-
require "fencepost/acts_as_fencepost"
|
3
2
|
require "fencepost/gate"
|
3
|
+
require "fencepost/acts_as_fencepost"
|
4
|
+
require "fencepost/configuration"
|
4
5
|
|
5
6
|
module Fencepost
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
self.configuration ||= Configuration.new
|
13
|
+
yield(configuration)
|
14
|
+
end
|
6
15
|
end
|
data/lib/fencepost/fencepost.rb
CHANGED
@@ -3,6 +3,7 @@ module Fencepost
|
|
3
3
|
attr_reader :gate
|
4
4
|
cattr_accessor :model_list
|
5
5
|
def initialize(params)
|
6
|
+
ensure_models
|
6
7
|
@gate = Gate.new(self.class.model_list, params)
|
7
8
|
self.class.models.each do |model|
|
8
9
|
define_singleton_method self.class.method_name(model) do
|
@@ -12,7 +13,7 @@ module Fencepost
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.models
|
15
|
-
ActiveRecord::Base.descendants
|
16
|
+
ActiveRecord::Base.descendants - [ActiveRecord::SchemaMigration]
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.generate_model_list
|
@@ -33,6 +34,13 @@ module Fencepost
|
|
33
34
|
model_list
|
34
35
|
end
|
35
36
|
|
37
|
+
def ensure_models
|
38
|
+
Rails.application.eager_load!
|
39
|
+
klass = self.class
|
40
|
+
if ::Fencepost.configuration.dev_mode
|
41
|
+
klass.model_list = klass.generate_model_list
|
42
|
+
end
|
43
|
+
end
|
36
44
|
|
37
45
|
def allow(elements)
|
38
46
|
gate.allow(elements)
|
data/lib/fencepost/gate.rb
CHANGED
@@ -56,8 +56,15 @@ module Fencepost
|
|
56
56
|
def set_permission_value(perm, key, value, operator)
|
57
57
|
if perm.is_a?(Hash) && perm.keys.index(key) && perm[key].is_a?(Array)
|
58
58
|
perm[key] = perm[key].send(operator, value)
|
59
|
-
|
60
|
-
|
59
|
+
recurse_permissions(perm, key, value, operator)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def recurse_permissions(perm, key, value, operator)
|
64
|
+
hash_values(perm[key]).each do |pk|
|
65
|
+
hash_values(value).each do |hk|
|
66
|
+
set_permission_value(pk, hk.keys[0], hk.values[0], operator)
|
67
|
+
end
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
data/lib/fencepost/version.rb
CHANGED
@@ -10,6 +10,16 @@ class FencepostConfigGenerator < Rails::Generators::Base
|
|
10
10
|
def file_contents
|
11
11
|
<<-yaml
|
12
12
|
Rails.application.eager_load!
|
13
|
+
Fencepost.configure do |config|
|
14
|
+
# dev_mode true means that the Fencepost model_list is created every time
|
15
|
+
# a Fencepost is created. This allows you to have Fencepost read your models
|
16
|
+
# dynamically rather than having to generate a new yaml file every time you
|
17
|
+
# want to change your models. Once your models have stabilized, however. You
|
18
|
+
# should set this to false and run bundle exec rails g fencepost_config for
|
19
|
+
# a performance gain (having the model graph as a class variable rather than
|
20
|
+
# creating it from scratch every time)
|
21
|
+
config.dev_mode = false
|
22
|
+
end
|
13
23
|
Fencepost::Fencepost.model_list = YAML.load(
|
14
24
|
<<-contents
|
15
25
|
#{Fencepost::Fencepost.generate_model_list.to_yaml}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fencepost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Helm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- lib/fencepost/acts_as_fencepost.rb
|
91
|
+
- lib/fencepost/configuration.rb
|
91
92
|
- lib/fencepost/fencepost.rb
|
92
93
|
- lib/fencepost/gate.rb
|
93
94
|
- lib/fencepost/version.rb
|