File: mixin.rb

package info (click to toggle)
ruby-morpher 0.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 520 kB
  • sloc: ruby: 2,366; makefile: 4
file content (58 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module Morpher
  class Printer

    # Printer behavior mixin
    module Mixin

      # Class level methods to be mixed in
      module ClassMethods

        # Register printer block for class
        #
        # @return [self]
        #
        # @api private
        #
        def printer(&block)
          REGISTRY[self] = block
        end

      end # ClassMethods

      # Instance level methods to be mixed in
      module InstanceMethods

        # Return description
        #
        # @return [String]
        #
        # @api private
        #
        def description
          io = StringIO.new
          Printer.run(self, io)
          io.rewind
          io.read
        end

      end # InstanceMethods

      # Callback whem module gets included
      #
      # @param [Class, Module] descendant
      #
      # @return [undefined]
      #
      # @api private
      #
      def self.included(descendant)
        descendant.class_eval do
          extend ClassMethods
          include InstanceMethods
        end
      end
      private_class_method :included

    end # Mixin
  end # Printer
end # Morpher