class Spina::Plugin
Attributes
name[RW]
namespace[RW]
settings[RW]
Private Class Methods
all()
click to toggle source
# File lib/spina/plugin.rb, line 48 def all ::Spina::PLUGINS end
find_by(opts={})
click to toggle source
# File lib/spina/plugin.rb, line 52 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| ... }
click to toggle source
# File lib/spina/plugin.rb, line 62 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
Public Instance Methods
create_setting_class!()
click to toggle source
# 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 include AttrJson::Record include Spina::AttrJsonMonkeypatch class_settings.each do |setting| attr_json *setting, container_attribute: "preferences" attr_json_setter_monkeypatch setting.first end default_scope { where(plugin: "#{plugin_name}") } end "Spina::#{namespace_class}".constantize.const_set 'Setting', klass end
Private Instance Methods
data_mapped_settings_hash()
click to toggle source
# File lib/spina/plugin.rb, line 38 def data_mapped_settings_hash hash = Hash.new settings.each do |key, value| hash[key] = map_data_type(value) end hash end
map_data_type(type)
click to toggle source
# File lib/spina/plugin.rb, line 26 def map_data_type(type) type = type.is_a?(Hash) ? type.first.first : type case type when :wysiwyg then :text else type end end
namespace_class()
click to toggle source
# File lib/spina/plugin.rb, line 34 def namespace_class namespace.split('_').map{|part| part.camelize}.join end