Module: Ronin::Mixin

Included in:
Network::Mixins::DNS, Network::Mixins::FTP, Network::Mixins::HTTP, Network::Mixins::IMAP, Network::Mixins::POP3, Network::Mixins::SMTP, Network::Mixins::SSL, Network::Mixins::TCP, Network::Mixins::UDP, Network::Mixins::UNIX
Defined in:
lib/ronin/mixin.rb

Overview

A base Module for all other Mixin modules. Adds a mixin method which includes/extends other Modules and evaluates a block of code, within any Classes/Objects it is included/extended into.

module MyMixin
  include Mixin

  mixin Paremters

  mixin do
    parameter :user, :default => 'admin'
  end
end

Since:

Class Method Summary (collapse)

Class Method Details

+ (Object) included(base)

Defines the mixin method when included.

Since:

  • 0.2.0



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ronin/mixin.rb', line 44

def self.included(base)
  base.module_eval do
    protected

    #
    # Mixins in the modules or code block into other modules that the
    # module might be included or extended into.
    #
    # @param [Array<Module>] modules
    #   Other modules to mixin.
    #
    # @yield []
    #   The given code block will be evaluated into the modules
    #   the module is included or extended into.
    #
    # @since 0.2.0
    #
    # @api semipublic
    #
    def self.mixin(*modules,&block)
      unless modules.empty?
        @mixin_modules = modules
      end

      @mixin_block = block if block

      def self.included(base)
        if @mixin_modules
          base.send(:include,*@mixin_modules)
        end

        base.module_eval(&@mixin_block) if @mixin_block
      end

      def self.extended(base)
        if @mixin_modules
          base.send(:extend,*@mixin_modules)
        end

        base.instance_eval(&@mixin_block) if @mixin_block
      end
    end
  end
end