walruz 0.0.8 → 0.0.9

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.
data/CHANGELOG CHANGED
@@ -1,15 +1,26 @@
1
+ * 0.0.9 (Aug 24, 2009) Policies deserve some love too
2
+ * Renamed the Walruz::Manager.check_authorization to
3
+ Walruz::Manager.check_action_authorization
4
+ * Added a new method Walruz::Manager.check_policy_authorization to be used on
5
+ the 'satisfies' methods.
6
+ * Moved the Walruz::Manager::QueryAuthorization extension from Walruz::Manager class
7
+ to Walruz main module
8
+ * Added a Walruz.version method that tells which version of Walruz you are
9
+ using
10
+
11
+
1
12
  * 0.0.8 (Aug 21, 2009) The anonymous who
2
- * New class <tt>Walruz::Manager</tt> will handle all the authorization
13
+ * New class Walruz::Manager will handle all the authorization
3
14
  invocation that was in Walruz::Actor and Walruz::Subject before
4
- * New module <tt>Walruz::Memoize</tt> that provides memoization methods to
5
- cache the result of the <tt>can?</tt>, <tt>authorize</tt>, <tt>satisfies?</tt>
6
- and <tt>satisfies</tt> methods in the Actor model
15
+ * New module Walruz::Memoize that provides memoization methods to
16
+ cache the result of the can?, authorize, satisfies?
17
+ and satisfies methods in the Actor model
7
18
  * Added the Walruz::Policy#halt method to stop execution of policies
8
19
  authorizations (even if they are in a composite policy), and return false with
9
- an error message.
20
+ an error message (given on the halt invocation).
10
21
 
11
22
  * 0.0.7 (July 23, 2009)
12
- * New +Array#only_authorized_for+ method for filtering arrays of _subjects_
13
- * Added the +satisfy+ on the +Walruz::Actor+ module
23
+ * New Array#only_authorized_for method for filtering arrays of subjects
24
+ * Added the satisfy on the Walruz::Actor module
14
25
  * Changed documentation from rDoc to YARD
15
26
  * Documented all the modules of the gem
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ begin
16
16
  end
17
17
 
18
18
  Jeweler::RubyforgeTasks.new do |rubyforge|
19
- rubyforge.doc_task = "yard"
19
+ rubyforge.doc_task = "yardoc"
20
20
  end
21
21
 
22
22
  rescue LoadError
@@ -39,6 +39,12 @@ end
39
39
 
40
40
  task :default => :spec
41
41
 
42
+ require 'yard'
43
+ YARD::Rake::YardocTask.new do |t|
44
+ t.files = ['lib/**/*.rb']
45
+ end
46
+
47
+
42
48
  require 'rake/rdoctask'
43
49
  Rake::RDocTask.new do |rdoc|
44
50
  if File.exist?('VERSION.yml')
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 8
4
+ :patch: 9
@@ -9,11 +9,11 @@ module Walruz
9
9
  module AuthorizationQuery
10
10
 
11
11
  def can?(actor, action, subject)
12
- Walruz::Manager.check_authorization(actor, action, subject)[0]
12
+ Walruz::Manager.check_action_authorization(actor, action, subject)[0]
13
13
  end
14
14
 
15
15
  def authorize!(actor, action, subject)
16
- result = Walruz::Manager.check_authorization(actor, action, subject)
16
+ result = Walruz::Manager.check_action_authorization(actor, action, subject)
17
17
  if result[0]
18
18
  result[1]
19
19
  else
@@ -24,29 +24,22 @@ module Walruz
24
24
  end
25
25
 
26
26
  def authorize(actor, action, subject)
27
- result = Walruz::Manager.check_authorization(actor, action, subject)
27
+ result = Walruz::Manager.check_action_authorization(actor, action, subject)
28
28
  result[0] ? result[1] : nil
29
29
  end
30
30
 
31
31
  def satisfies?(actor, policy_label, subject)
32
- policy_clz = Walruz.fetch_policy(policy_label)
33
- result = policy_clz.return_policy.new.safe_authorized?(actor, subject)
32
+ result = Walruz::Manager.check_policy_authorization(actor, policy_label, subject)
34
33
  result[0]
35
34
  end
36
35
 
37
36
  def satisfies(actor, policy_label, subject)
38
- policy_clz = Walruz.fetch_policy(policy_label)
39
- result = policy_clz.return_policy.new.safe_authorized?(actor, subject)
37
+ result = Walruz::Manager.check_policy_authorization(actor, policy_label, subject)
40
38
  result[0] ? result[1] : nil
41
39
  end
42
40
 
43
41
  end
44
42
 
45
- extend AuthorizationQuery
46
- class << self
47
- include Memoization
48
- walruz_memoize :can?, :authorize, :satisfies?, :satisfies
49
- end
50
43
 
51
44
  #
52
45
  # core method used on all the actor methods:
@@ -54,8 +47,8 @@ module Walruz
54
47
  # authorize!
55
48
  # authorize
56
49
  # :private:
57
- def self.check_authorization(actor, action, subject)
58
- check_authorization_action_is_declared_on_subject(subject, action)
50
+ def self.check_action_authorization(actor, action, subject)
51
+ check_action_authorization_is_declared_on_subject(subject, action)
59
52
  action = if subject.class._walruz_policies.key?(:default)
60
53
  subject.class._walruz_policies.key?(action) ? action : :default
61
54
  else
@@ -73,14 +66,27 @@ module Walruz
73
66
  new.
74
67
  safe_authorized?(actor, subject)
75
68
  rescue PolicyHalted => e
76
- result = [false, {:error_message => e.message}]
69
+ result = [false, {:error_message => e.message }]
77
70
  end
71
+
78
72
  result
79
73
  end
80
74
 
75
+ def self.check_policy_authorization(actor, policy_label, subject)
76
+ policy_clz = Walruz.fetch_policy(policy_label)
77
+
78
+ begin
79
+ result = policy_clz.return_policy.new.safe_authorized?(actor, subject)
80
+ rescue PolicyHalted => e
81
+ result = [false, { :error_message => e.message }]
82
+ end
83
+
84
+ result
85
+ end
86
+
81
87
  private
82
88
 
83
- def self.check_authorization_action_is_declared_on_subject(subject, action)
89
+ def self.check_action_authorization_is_declared_on_subject(subject, action)
84
90
  if subject.class._walruz_policies.nil?
85
91
  message =<<-BEGIN
86
92
  You need to invoke `check_authorizations :#{action} => Policies::SomePolicy` on the #{subject.class.name} class
data/lib/walruz.rb CHANGED
@@ -48,6 +48,12 @@ module Walruz
48
48
  autoload :Utils, base_path + '/walruz/utils'
49
49
 
50
50
 
51
+ def self.version
52
+ require "yaml"
53
+ version = YAML.load_file(File.dirname(__FILE__) + "/../VERSION.yml")
54
+ "%s.%s.%s" % [version[:major], version[:minor], version[:patch]]
55
+ end
56
+
51
57
  def self.setup
52
58
  config = Config.new
53
59
  yield config
@@ -89,6 +95,14 @@ module Walruz
89
95
  end
90
96
 
91
97
  end
98
+
99
+ # including the Walruz::Manager::AuthorizationQuery methods
100
+
101
+ extend Manager::AuthorizationQuery
102
+ class << self
103
+ include Memoization
104
+ walruz_memoize :can?, :authorize, :satisfies?, :satisfies
105
+ end
92
106
 
93
107
  end
94
108
 
@@ -68,16 +68,16 @@ describe 'Walruz::Actor' do
68
68
  describe '#can?' do
69
69
 
70
70
  it "should be invoked only the first time and then return a cached solution" do
71
- Walruz::Manager.should_receive(:check_authorization).once.and_return([true, {}])
71
+ Walruz::Manager.should_receive(:check_action_authorization).once.and_return([true, {}])
72
72
  Beatle::JOHN.can?(:sing, Song::YELLOW_SUBMARINE, :reload)
73
73
  Beatle::JOHN.can?(:sing, Song::YELLOW_SUBMARINE)
74
74
  end
75
75
 
76
76
  it "if a :reload symbol is passed as the third parameter it should not use the cached result" do
77
- Walruz::Manager.stub!(:check_authorization).and_return([true, {}])
77
+ Walruz::Manager.stub!(:check_action_authorization).and_return([true, {}])
78
78
  Beatle::JOHN.can?(:sing, Song::ALL_YOU_NEED_IS_LOVE).should be_true
79
79
 
80
- Walruz::Manager.stub!(:check_authorization).and_return([false, {}])
80
+ Walruz::Manager.stub!(:check_action_authorization).and_return([false, {}])
81
81
  Beatle::JOHN.can?(:sing, Song::ALL_YOU_NEED_IS_LOVE).should be_true
82
82
  Beatle::JOHN.can?(:sing, Song::ALL_YOU_NEED_IS_LOVE, :reload).should be_false
83
83
  end
@@ -5,7 +5,7 @@ describe Walruz::Manager do
5
5
  describe "#check_authorization" do
6
6
 
7
7
  it "should invoke the policies associated to an action on a subject performed by an actor" do
8
- result = Walruz::Manager.check_authorization(Beatle::JOHN, :sing, Song::ALL_YOU_NEED_IS_LOVE)
8
+ result = Walruz::Manager.check_action_authorization(Beatle::JOHN, :sing, Song::ALL_YOU_NEED_IS_LOVE)
9
9
  result[0].should be_true
10
10
  end
11
11
 
@@ -13,7 +13,7 @@ describe Walruz::Manager do
13
13
 
14
14
  it "should raise an Walruz::AuthorizationActionsNotDefined error" do
15
15
  lambda do
16
- Walruz::Manager.check_authorization(Beatle::JOHN, :talk_with, Beatle::PAUL)
16
+ Walruz::Manager.check_action_authorization(Beatle::JOHN, :talk_with, Beatle::PAUL)
17
17
  end.should raise_error(Walruz::AuthorizationActionsNotDefined)
18
18
  end
19
19
 
@@ -6,7 +6,7 @@ describe Walruz do
6
6
  Walruz.should respond_to(:policies)
7
7
  end
8
8
 
9
- describe '#policies' do
9
+ describe '.policies' do
10
10
 
11
11
  it "should return all the policies created that have a label" do
12
12
  Walruz.policies.should_not be_nil
@@ -17,7 +17,7 @@ describe Walruz do
17
17
 
18
18
  end
19
19
 
20
- describe "#fetch_policy" do
20
+ describe ".fetch_policy" do
21
21
 
22
22
  it "should grab the policy if this is registered" do
23
23
  Walruz.fetch_policy(:in_colaboration).should == AuthorInColaborationPolicy
@@ -31,4 +31,13 @@ describe Walruz do
31
31
 
32
32
  end
33
33
 
34
- end
34
+ describe ".version" do
35
+
36
+ it "should return a string representing the current version" do
37
+ version = YAML.load_file(File.dirname(__FILE__) + "/../../VERSION.yml")
38
+ Walruz.version.should == "#{version[:major]}.#{version[:minor]}.#{version[:patch]}"
39
+ end
40
+
41
+ end
42
+
43
+ end
data/walruz.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{walruz}
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Roman Gonzalez"]
12
- s.date = %q{2009-08-21}
12
+ s.date = %q{2009-08-24}
13
13
  s.email = %q{roman@noomi.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: walruz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Gonzalez
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-21 00:00:00 -07:00
12
+ date: 2009-08-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15