Class: Mobility::Pluggable

Inherits:
Module
  • Object
show all
Defined in:
lib/mobility/pluggable.rb

Overview

Abstract Module subclass with methods to define plugins and defaults. Works with Plugin. (Subclassed by Translations.)

Direct Known Subclasses

Translations

Defined Under Namespace

Classes: InvalidOptionKey

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Pluggable

Returns a new instance of Pluggable.



34
35
36
37
# File 'lib/mobility/pluggable.rb', line 34

def initialize(*, **options)
  initialize_options(options)
  validate_options(@options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



39
40
41
# File 'lib/mobility/pluggable.rb', line 39

def options
  @options
end

Class Method Details

.defaultsObject



24
25
26
# File 'lib/mobility/pluggable.rb', line 24

def defaults
  @defaults ||= {}
end

.included_pluginsObject



20
21
22
# File 'lib/mobility/pluggable.rb', line 20

def included_plugins
  included_modules.grep(Plugin)
end

.inherited(klass) ⇒ Object



28
29
30
31
# File 'lib/mobility/pluggable.rb', line 28

def inherited(klass)
  super
  klass.defaults.merge!(defaults)
end

.plugin(name, *args) ⇒ Object



12
13
14
# File 'lib/mobility/pluggable.rb', line 12

def plugin(name, *args)
  Plugin.configure(self, defaults) { __send__ name, *args }
end

.plugins(&block) ⇒ Object



16
17
18
# File 'lib/mobility/pluggable.rb', line 16

def plugins(&block)
  Plugin.configure(self, defaults, &block)
end