Module: Pincushion::Plugins

Included in:
RootModuleMethods
Defined in:
lib/pincushion/plugins.rb,
lib/pincushion/plugins/csv_serializer.rb,
lib/pincushion/plugins/json_serializer.rb

Defined Under Namespace

Modules: CsvSerializer, JsonSerializer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pluginsObject (readonly)

Returns the value of attribute plugins.



25
26
27
# File 'lib/pincushion/plugins.rb', line 25

def plugins
  @plugins
end

Class Method Details

.camelize(string) ⇒ Object



19
20
21
22
23
# File 'lib/pincushion/plugins.rb', line 19

def self.camelize(string)
  string.to_s
    .gsub(/\/(.?)/) { "::" + Regexp.last_match(1).upcase }
    .gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase }
end

Instance Method Details

#plugin(name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pincushion/plugins.rb', line 27

def plugin(name)
  require "pincushion/plugins/#{name}"
  mod = Plugins.const_get(Plugins.camelize(name))
  extend mod::ModuleMethods if defined?(mod::ModuleMethods)
  extend mod::RootModuleMethods if defined?(mod::RootModuleMethods)
  include mod::InstanceMethods if defined?(mod::InstanceMethods)
  @plugins ||= []
  @plugins << name
rescue LoadError
  raise LoadError, "Plugin not found: #{name}"
rescue NameError => e
  raise NameError, "#{e} for plugin: #{name}"
end