Sha256: 14b6bf06ebac9f098978cbae12e1d34fcd58647c8064d610b898af93ab9db56b

Contents?: true

Size: 938 Bytes

Versions: 2

Compression:

Stored size: 938 Bytes

Contents

require 'moosex'
require 'moosex/attribute'

module MooseX
  module AttributeModifiers
    module ThirdParty
      class Chained
        def initialize(this)
          @this = this
        end
        def process(options, attr_symbol)
         
         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
         
         chained
        end
     end
    end
  end  
end

module MyPlugin
  def self.included(x)
    x.meta.add_plugin(:chained)
  end
end

class Z
  include MooseX.init(meta: true)
  include MyPlugin

  has :foo, {
    writter: :set_foo,
    chained: true,
  }
  
  has :bar, {
    writter: :set_bar,
    chained: false,
  }
end

a1 = Z.new
a2 = Z.new

puts a1.set_foo(1).foo

puts a2.set_bar(1)#.bar

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
moosex-0.0.21 samples/plugin.rb
moosex-0.0.20 samples/plugin.rb