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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.camelize(string) ⇒ Object



3
4
5
6
7
# File 'lib/pincushion/plugins.rb', line 3

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



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pincushion/plugins.rb', line 9

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)
rescue LoadError
  raise LoadError, "Plugin not found: #{name}"
rescue NameError => e
  raise NameError, "#{e} for plugin: #{name}"
end