Class: Spina::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/spina/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/spina/plugin.rb', line 4

def name
  @name
end

#namespaceObject

Returns the value of attribute namespace.



4
5
6
# File 'lib/spina/plugin.rb', line 4

def namespace
  @namespace
end

#settingsObject

Returns the value of attribute settings.



4
5
6
# File 'lib/spina/plugin.rb', line 4

def settings
  @settings
end

Class Method Details

.allObject



42
43
44
# File 'lib/spina/plugin.rb', line 42

def all
  ::Spina::PLUGINS
end

.find_by(opts = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/spina/plugin.rb', line 46

def find_by(opts={})
  all.find do |plugin|
    matches = true
    opts.each do |key, value|
      matches = false unless plugin.send(key) == value
    end
    plugin if matches
  end
end

.register {|plugin| ... } ⇒ Object

Yields:

  • (plugin)


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/spina/plugin.rb', line 56

def register
  plugin = new
  yield plugin
  raise 'Missing plugin name' if plugin.name.nil?
  raise 'Missing plugin namespace' if plugin.namespace.nil?

  if plugin.settings.present?
    plugin.create_setting_class!
  end

  all << plugin
  plugin
end

Instance Method Details

#create_setting_class!Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/spina/plugin.rb', line 6

def create_setting_class!
  class_settings = data_mapped_settings_hash
  plugin_name = namespace

  klass = Class.new(::Spina::Setting) do
    jsonb_accessor :preferences, class_settings

    default_scope { where(plugin: "#{plugin_name}") }
  end
  "Spina::#{namespace_class}".constantize.const_set 'Setting', klass
end