Class: Sunrise::Plugin
- Inherits:
-
Object
- Object
- Sunrise::Plugin
- Defined in:
- lib/sunrise/plugin.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#klass_name ⇒ Object
Returns the value of attribute klass_name.
-
#menu ⇒ Object
Returns the value of attribute menu.
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name) ⇒ Plugin
constructor
A new instance of Plugin.
- #module_name ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(name) ⇒ Plugin
Returns a new instance of Plugin.
5 6 7 8 9 10 11 12 |
# File 'lib/sunrise/plugin.rb', line 5 def initialize(name) @name = name.to_s.downcase @menu = false @klass = nil @klass_name = nil Sunrise::Plugins.registered << self end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/sunrise/plugin.rb', line 3 def klass @klass end |
#klass_name ⇒ Object
Returns the value of attribute klass_name.
3 4 5 |
# File 'lib/sunrise/plugin.rb', line 3 def klass_name @klass_name end |
#menu ⇒ Object
Returns the value of attribute menu.
3 4 5 |
# File 'lib/sunrise/plugin.rb', line 3 def @menu end |
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'lib/sunrise/plugin.rb', line 3 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/sunrise/plugin.rb', line 3 def name @name end |
#version ⇒ Object
Returns the value of attribute version.
3 4 5 |
# File 'lib/sunrise/plugin.rb', line 3 def version @version end |
Class Method Details
.register(name) {|plugin| ... } ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sunrise/plugin.rb', line 30 def self.register(name, &block) plugin = self.new(name) yield plugin raise "A plugin MUST have a name!: #{plugin.inspect}" if plugin.name.blank? plugin.version ||= Sunrise::VERSION.dup if plugin.model [plugin.model].flatten.each do |model| module_name = plugin.module_name model_path = "sunrise/models/#{plugin.name}" case model when String then model_path = model when Symbol then model_name = model.to_s.singularize module_name = model_name.camelize.to_sym model_path = "sunrise/models/#{model_name}" end Sunrise::Models.send(:autoload, module_name, model_path) end end end |
Instance Method Details
#module_name ⇒ Object
14 15 16 |
# File 'lib/sunrise/plugin.rb', line 14 def module_name @module_name ||= @name.singularize.camelize.to_sym end |
#title ⇒ Object
26 27 28 |
# File 'lib/sunrise/plugin.rb', line 26 def title I18n.t(@name, :scope => [:manage, :plugins]) end |