lib/moosex/plugins.rb in moosex-0.0.20 vs lib/moosex/plugins.rb in moosex-0.0.21

- old
+ new

@@ -1,8 +1,12 @@ module MooseX module Plugins class Chained + def prepare(options) + + end + def initialize(this) @this = this end def process(options) chained = !! options.delete(:chained) @@ -19,41 +23,40 @@ class ExpiredAttribute def initialize(this) @this = this end + + def prepare(options) + if(options[:expires]) + options[:traits] ||= [] + options[:traits].unshift( MooseX::Traits::Expires.with(options[:expires]) ) + + unless options[:clearer] + options[:clearer] = true + end + end + end + def process(options) expires = options.delete(:expires) || nil if expires lazy = @this.attribute_map[:lazy] clearer = @this.attribute_map[:clearer] - predicate = @this.attribute_map[:predicate] reader = @this.attribute_map[:reader] - writter = @this.attribute_map[:writter] - old_traits= @this.attribute_map[:traits] - - @this.attribute_map[:traits] = ->(this) do - MooseX::Traits::Expires.new([ old_traits.call(this), expires ]) - end - if reader && clearer && lazy - reader_proc = @this.generate_reader + reader_proc = @this.methods[reader] @this.methods[reader] = ->(this) do - x = reader_proc.call(this) - unless x.valid? + value = reader_proc.call(this) + unless value.valid? this.__send__(clearer) - x = reader_proc.call(this) + value = reader_proc.call(this) end - x + value end - elsif reader - @this.methods[reader] = @this.generate_reader end - if writter - @this.methods[writter] = @this.generate_writter - end end @this.attribute_map[:expires] = expires end end \ No newline at end of file