Module: Subserver::Subscriber::ClassMethods

Defined in:
lib/subserver/subscriber.rb

Instance Method Summary collapse

Instance Method Details

#auto_subscribe?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/subserver/subscriber.rb', line 14

def auto_subscribe?
  respond_to? :auto_subscribe
end

#get_subserver_optionsObject



22
23
24
# File 'lib/subserver/subscriber.rb', line 22

def get_subserver_options
  self.subserver_options_hash ||= Subserver.default_subscriber_options
end

#subserver_class_attribute(*attrs) ⇒ Object



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
# File 'lib/subserver/subscriber.rb', line 26

def subserver_class_attribute(*attrs)
  instance_reader = true
  instance_writer = true

  attrs.each do |name|
    singleton_class.instance_eval do
      undef_method(name) if method_defined?(name) || private_method_defined?(name)
    end
    define_singleton_method(name) { nil }

    ivar = "@#{name}"

    singleton_class.instance_eval do
      m = "#{name}="
      undef_method(m) if method_defined?(m) || private_method_defined?(m)
    end
    define_singleton_method("#{name}=") do |val|
      singleton_class.class_eval do
        undef_method(name) if method_defined?(name) || private_method_defined?(name)
        define_method(name) { val }
      end

      if singleton_class?
        class_eval do
          undef_method(name) if method_defined?(name) || private_method_defined?(name)
          define_method(name) do
            if instance_variable_defined? ivar
              instance_variable_get ivar
            else
              singleton_class.send name
            end
          end
        end
      end
      val
    end

    if instance_reader
      undef_method(name) if method_defined?(name) || private_method_defined?(name)
      define_method(name) do
        if instance_variable_defined?(ivar)
          instance_variable_get ivar
        else
          self.class.public_send name
        end
      end
    end

    if instance_writer
      m = "#{name}="
      undef_method(m) if method_defined?(m) || private_method_defined?(m)
      attr_writer name
    end
  end
end

#subserver_options(opts = {}) ⇒ Object



18
19
20
# File 'lib/subserver/subscriber.rb', line 18

def subserver_options(opts={})
  self.subserver_options_hash = get_subserver_options.merge(opts)
end