Sha256: e203391224db60feae443f75758b19ec62af00869a140a85a31dc3385e459285

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

module MooseX
  module Plugins
    class Chained
      def initialize(this)
        @this = this
      end
      def process(options)
       chained = !! options.delete(:chained)

       if chained
         writter  = @this.attribute_map[:writter]
         old_proc = @this.methods[ writter ]
         @this.methods[writter] = ->(this, value) { old_proc.call(this, value); this }   
       end

      @this.attribute_map[:chained] = chained
      end
    end
    
    class ExpiredAttribute
      def initialize(this)
        @this = this
      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
           @this.methods[reader]  = ->(this) do
             x = reader_proc.call(this)
             unless x.valid?
               this.__send__(clearer)
               x = reader_proc.call(this)
             end
             x
           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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
moosex-0.0.20 lib/moosex/plugins.rb