File: actor_class.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (123 lines) | stat: -rw-r--r-- 2,401 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
class ExampleCrash < Celluloid::Error
  attr_accessor :foo
end

module ExampleActorClass
  def self.create(included_module, task_klass)
    Class.new do
      include included_module
      task_class task_klass
      attr_reader :name
      finalizer :my_finalizer
      execute_block_on_receiver :run_on_receiver

      def initialize(name)
        @name = name
        @delegate = [:bar]
      end

      def sleepy(duration)
        sleep duration
      end

      def change_name(new_name)
        @name = new_name
      end

      def change_name_async(new_name)
        async.change_name new_name
      end

      def greet
        "Hi, I'm #{@name}"
      end

      def actor?
        Celluloid.actor?
      end

      def run(*args)
        yield(*args)
      end

      def run_on_receiver(*args)
        yield(*args)
      end

      def crash
        raise ExampleCrash, "the spec purposely crashed me :("
      end

      def crash_with_abort(reason, foo = nil)
        example_crash = ExampleCrash.new(reason)
        example_crash.foo = foo
        abort example_crash
      end

      def crash_with_abort_raw(reason)
        abort reason
      end

      def internal_hello
        external_hello
      end

      def external_hello
        "Hello"
      end

      def inspect_thunk
        inspect
      end

      def send(string)
        string.reverse
      end

      def shutdown
        terminate
      end

      # Ideally, this class should implement "fake methods"
      # consistently, including :methods, :public_methods, etc.
      def method_missing(method_name, *args, &block)
        if delegates?(method_name)
          @delegate.send method_name, *args, &block
        else
          super
        end
      end

      def respond_to?(method_name, include_private = false)
        delegates?(method_name) || super
      end

      def method(method_name)
        if delegates?(method_name)
          @delegate.method(method_name)
        else
          super
        end
      end

      def call_private
        async.zomg_private
      end

      def zomg_private
        @private_called = true
      end
      private :zomg_private
      attr_reader :private_called

      def my_finalizer; end

      private

      def delegates?(method_name)
        return false unless @delegate ||= nil
        @delegate.respond_to?(method_name)
      end
    end
  end
end