Class: ActsAsMessageable::Rails3

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/acts_as_messageable/rails3.rb

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ Rails3

Returns a new instance of Rails3.



13
14
15
# File 'lib/acts_as_messageable/rails3.rb', line 13

def initialize(subject)
  @subject = subject
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



34
35
36
# File 'lib/acts_as_messageable/rails3.rb', line 34

def method_missing(name, *args)
  T.unsafe(@subject).send(name, *args) || super
end

Instance Method Details

#default_scope(order_by) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/acts_as_messageable/rails3.rb', line 21

def default_scope(order_by)
  # T.unsafe is needed here because the default_scope method is defined in
  # different ways in different versions of Rails. In Rails 3, it is a
  # class method, but in Rails 4, it is an instance method. We can't
  # statically determine which version of Rails is being used, so we have
  # to use T.unsafe here.
  @subject.send(:default_scope, T.unsafe(@subject).order(order_by))
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/acts_as_messageable/rails3.rb', line 42

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s == 'default_scope' || super
end