Sha256: 2f0b9afaff8b8d38664434972520587b6607f782440e6e6cb423ca77538fcf6e

Contents?: true

Size: 873 Bytes

Versions: 4

Compression:

Stored size: 873 Bytes

Contents

module Schizo

  # Extend a module with Role to make that module a _role_.
  #   module RoleA
  #     extend Schizo::Role
  #
  #     def method_a
  #     end
  #
  #     def method_b
  #     end
  #   end
  module Role

    # call-seq:
    #   extended{ ... }
    #
    # Call this method with a block and that block will be evaled by the Data object's class when
    # the Data object is adorned with this role.
    #   module Poster
    #     extend Schizo::Role
    #
    #     extended do
    #       has_many :posts
    #     end
    #   end
    #
    #   User.new.as(Poster).do |poster|
    #     poster.posts.create :title => "My first post!"
    #   end
    def extended(object = nil, &block)
      if block_given?
        @extended_block = block
      else
        super
      end
    end

    def extended_block #:nodoc:
      @extended_block
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
schizo-0.2.0 lib/schizo/role.rb
schizo-0.1.3 lib/schizo/role.rb
schizo-0.1.2 lib/schizo/role.rb
schizo-0.1.1 lib/schizo/role.rb