heimdallr 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ module Heimdallr
2
+ # This is an internal class which runs security validations when {Proxy::Record#save}
3
+ # and {Proxy::Record#save!} are invoked. +ActiveRecord::Base#save+ (and +save!+) clears
4
+ # the +errors+ object internally, so this hack is required to avoid monkey-patching it.
5
+ class Validator < ActiveModel::Validator
6
+ # Run the +record.heimdallr_validators+ on the current record, if any.
7
+ def validate(record)
8
+ if record.heimdallr_validators
9
+ record.heimdallr_validators.each do |validator|
10
+ validator.validate(record)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heimdallr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-02 00:00:00.000000000 Z
12
+ date: 2012-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &80513130 !ruby/object:Gem::Requirement
16
+ requirement: &83064660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *80513130
24
+ version_requirements: *83064660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activemodel
27
- requirement: &80522090 !ruby/object:Gem::Requirement
27
+ requirement: &83064350 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *80522090
35
+ version_requirements: *83064350
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &80518720 !ruby/object:Gem::Requirement
38
+ requirement: &83064110 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *80518720
46
+ version_requirements: *83064110
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activerecord
49
- requirement: &79906240 !ruby/object:Gem::Requirement
49
+ requirement: &83063840 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *79906240
57
+ version_requirements: *83063840
58
58
  description: ! "Heimdallr aims to provide an easy to configure and efficient object-
59
59
  and field-level access\n control solution, reusing proven patterns from gems like
60
- CanCan and allowing one to control permissions in a very\n fine-grained manner."
60
+ CanCan and allowing one to manage permissions in a very\n fine-grained manner."
61
61
  email:
62
62
  - whitequark@whitequark.org
63
63
  executables: []
@@ -66,15 +66,20 @@ extra_rdoc_files: []
66
66
  files:
67
67
  - .gitignore
68
68
  - .rspec
69
+ - .yardopts
69
70
  - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - README.yard.md
70
74
  - Rakefile
71
75
  - heimdallr.gemspec
72
76
  - lib/heimdallr.rb
73
77
  - lib/heimdallr/evaluator.rb
74
78
  - lib/heimdallr/model.rb
75
- - lib/heimdallr/proxy.rb
79
+ - lib/heimdallr/proxy/collection.rb
80
+ - lib/heimdallr/proxy/record.rb
76
81
  - lib/heimdallr/resource.rb
77
- - lib/heimdallr/version.rb
82
+ - lib/heimdallr/validator.rb
78
83
  - spec/proxy_spec.rb
79
84
  - spec/spec_helper.rb
80
85
  homepage: http://github.com/roundlake/heimdallr
@@ -103,3 +108,4 @@ specification_version: 3
103
108
  summary: Heimdallr is an ActiveModel extension which provides object- and field-level
104
109
  access control.
105
110
  test_files: []
111
+ has_rdoc:
@@ -1,61 +0,0 @@
1
- module Heimdallr
2
- class Proxy
3
- def initialize(context, action, object)
4
- @context, @action, @object = context, action, object
5
-
6
- @whitelist = @object.class.restrictions(context).whitelist[@action]
7
- end
8
-
9
- def self.filter_attributes(attributes, whitelist)
10
- attributes.delete_if do |key, value|
11
- !whitelist.include?(key)
12
- end
13
-
14
- attributes
15
- end
16
-
17
- def attributes
18
- self.class.filter_attributes(@object.attributes, @whitelist)
19
- end
20
-
21
- def update_attributes(attributes)
22
- @object.update_attributes(self.class.filter_attributes(attributes, @whitelist))
23
- end
24
-
25
- def update_attributes!(attributes)
26
- @object.update_attributes!(self.class.filter_attributes(attributes, @whitelist))
27
- end
28
-
29
- def method_missing(method, *args)
30
- if method.to_s.ends_with?("?") || method.to_s.ends_with?("=")
31
- normalized_method = method[0..-2].to_sym
32
- else
33
- normalized_method = method
34
- end
35
-
36
- if defined?(ActiveRecord) && @object.is_a?(ActiveRecord::Base) &&
37
- association = @object.class.reflect_on_association(method)
38
- if association.collection?
39
- raise "not implemented"
40
- else
41
- referenced = @object.send(method, *args)
42
- if referenced.respond_to? :to_proxy
43
- referenced.to_proxy(@context, @action)
44
- else
45
- referenced
46
- end
47
- end
48
- elsif @whitelist.include? normalized_method
49
- @object.send method, *args
50
- elsif @object.respond_to? method
51
- nil
52
- else
53
- super
54
- end
55
- end
56
-
57
- def inspect
58
- "#<Heimdallr::Proxy(#{@whitelist.join ", "}): #{@object.inspect}>"
59
- end
60
- end
61
- end
@@ -1,3 +0,0 @@
1
- module Heimdallr
2
- VERSION = "0.0.1"
3
- end