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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adcf26d9b1d1745070a32eb1f8571c3210e5e057
4
- data.tar.gz: 340c6a88f0f73738044c2e8ae6b51c482f0d6921
3
+ metadata.gz: f017e22be8ba3a0e67b270a401d2fb331cf33ebc
4
+ data.tar.gz: 409354913b4fbbc7b0c99533b0a068e6ae81423b
5
5
  SHA512:
6
- metadata.gz: 2d885cf5947235413d44408024675493d910439ce6561b69a9ab27ad879a08bb5ad77cd241077b25b1a6b5e304b14228842624a919c8baa88b88203f889e51d2
7
- data.tar.gz: 4202a2f4be00570a36e257bae65f092d9a448a7e453ab5de2a787a2706e47eebe822eba8393ca07af27a117a0b3ea62d953ce7e2eac12122c2ec739ecbb73f17
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
@@ -0,0 +1,9 @@
1
+ module Fencepost
2
+ class Configuration
3
+ attr_accessor :dev_mode
4
+
5
+ def initialize
6
+ @dev_mode = false
7
+ end
8
+ end
9
+ end
@@ -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)
@@ -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
- elsif perm.is_a?(Hash) && perm.keys.index(key) && perm[key].is_a?(Hash)
60
- perm[key] = nested_denies(perm[key], value)
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
 
@@ -1,3 +1,3 @@
1
1
  module Fencepost
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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.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 00:00:00.000000000 Z
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