Skip to content

Commit

Permalink
updated use of stamper in custom ability
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Aug 7, 2011
1 parent 77597af commit c376223
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -32,7 +32,8 @@ group :test do
gem "launchy"

# Debug
gem 'cutter'
gem 'cutter', '>= 0.5', :git => "git://github.com/kristianmandrup/cutter.git"
gem 'colorize'

# Rails
gem 'haml'
Expand Down
29 changes: 19 additions & 10 deletions spec/integration/performance/helpers/ability.rb
@@ -1,3 +1,10 @@
Stamper.scope :ability => "Ability#initialize" do |stan|
stan.msg :no_cache => 'No caching, going through engines'
stan.msg :permissions_done => "Permissions finished"
stan.msg :permits_done => "Permits finished"
stan.msg :caching_done => "Caching finished"
end

module CanTango
class Ability
def initialize candidate, options = {}
Expand All @@ -14,9 +21,9 @@ def initialize candidate, options = {}

puts "\nAbility#initialize"

stamper("No caching, going through engines:") {
stamper( {

stamper("Ability#initialize") {
stamper(:ability) {
raise "Candidate must be something!" if !candidate
@candidate, @options = candidate, options
@session = options[:session] || {} # seperate session cache for each type of user?
Expand All @@ -28,21 +35,23 @@ def initialize candidate, options = {}
return
end if cached_rules?

stamper("Ability#initialize: No caching, going through engines:") {
with(:permissions) {|permission| permission.evaluate! user }
stamp "Permissions finished"
with(:permits) {|permit| break if permit.execute == :break }
stamp "Permits finished"
stamper(:ability) {
stamp(:no_cache)
with(:permissions) {|permission| permission.evaluate! user }
stamp :permissions_done

with(:permits) {|permit| break if permit.execute == :break }
stamp :permits_done

with(:permissions) {|permission| permission.evaluate! user }

stamp "Permissions finished"
stamp :permissions_done

with(:permits) {|permit| break if permit.execute == :break }
stamp "Permits finished"
stamp :permits_done

cache_rules!
stamp "Caching finished"
stamp :caching_done
}
end
end
Expand Down

0 comments on commit c376223

Please sign in to comment.