Module: Rubikon::Application::ClassMethods

Included in:
Base
Defined in:
lib/rubikon/application/class_methods.rb

Overview

This module contains all class methods of Application::Base and its subclasses.

See Also:

Author:

  • Sebastian Staudt

Since:

  • 0.2.0

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)

This is used for convinience. Method calls on the class itself are relayed to the singleton instance.

This is called automatically when calling methods on the application class.

Parameters:

  • method_name (Symbol)

    The name of the method being called

  • args (Array)

    Any arguments that are given to the method

  • block (Proc)

    A block that may be given to the method

Since:

  • 0.2.0



53
54
55
# File 'lib/rubikon/application/class_methods.rb', line 53

def method_missing(method_name, *args, &block)
  instance.send(method_name, *args, &block)
end

Instance Method Details

#autorun?Boolean (private)

Returns whether this application should be run automatically

Returns:

  • (Boolean)

Since:

  • 0.2.0



23
24
25
# File 'lib/rubikon/application/class_methods.rb', line 23

def autorun?
  instance.instance_variable_get(:@settings)[:autorun] || false
end

#inherited(subclass) ⇒ Object (private)

Enables autorun functionality using Kernel#at_exit

This is called automatically when subclassing Application::Base.

Parameters:

  • subclass (Class)

    The subclass inheriting from Application::Base. This is the user’s application.

Since:

  • 0.2.0



34
35
36
37
38
39
40
41
42
# File 'lib/rubikon/application/class_methods.rb', line 34

def inherited(subclass)
  subclass.class_eval { include Singleton }
  subclass.send(:base_file=, File.expand_path(caller.first.split(':').first))
  at_exit do
    if subclass.send(:autorun?)
      InstanceMethods.instance_method(:run).bind(subclass.instance).call
    end
  end
end