Class: Challah::Plugins::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/challah/plugins.rb

Overview

A simple DSL for registering a plugin

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



8
9
10
11
12
13
# File 'lib/challah/plugins.rb', line 8

def initialize
  @active_record ||= []
  @action_controller ||= []
  @user_extensions ||= []
  @user_init_methods ||= []
end

Instance Attribute Details

#action_controllerObject (readonly)

Returns the value of attribute action_controller.



6
7
8
# File 'lib/challah/plugins.rb', line 6

def action_controller
  @action_controller
end

#active_recordObject (readonly)

Returns the value of attribute active_record.



6
7
8
# File 'lib/challah/plugins.rb', line 6

def active_record
  @active_record
end

#user_extensionsObject (readonly)

Returns the value of attribute user_extensions.



6
7
8
# File 'lib/challah/plugins.rb', line 6

def user_extensions
  @user_extensions
end

#user_init_methodsObject (readonly)

Returns the value of attribute user_init_methods.



6
7
8
# File 'lib/challah/plugins.rb', line 6

def user_init_methods
  @user_init_methods
end

Instance Method Details

#extend_user(module_name, init_method = nil) ⇒ Object

Pass a module name to include it in the base User model after challah_user is run



23
24
25
26
# File 'lib/challah/plugins.rb', line 23

def extend_user(module_name, init_method = nil)
  @user_extensions << module_name
  @user_init_methods << init_method unless init_method.nil?
end

#on_load(framework, &block) ⇒ Object

When active_record or action_controller is loaded, run the given block



16
17
18
19
# File 'lib/challah/plugins.rb', line 16

def on_load(framework, &block)
  return unless [ :active_record, :action_controller ].include?(framework)
  instance_variable_get("@#{framework}") << block
end