Class: Sunrise::Plugin

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#klassObject

Returns the value of attribute klass.



3
4
5
# File 'lib/sunrise/plugin.rb', line 3

def klass
  @klass
end

#klass_nameObject

Returns the value of attribute klass_name.



3
4
5
# File 'lib/sunrise/plugin.rb', line 3

def klass_name
  @klass_name
end

Returns the value of attribute menu.



3
4
5
# File 'lib/sunrise/plugin.rb', line 3

def menu
  @menu
end

#modelObject

Returns the value of attribute model.



3
4
5
# File 'lib/sunrise/plugin.rb', line 3

def model
  @model
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/sunrise/plugin.rb', line 3

def name
  @name
end

#versionObject

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

Yields:

  • (plugin)


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_nameObject



14
15
16
# File 'lib/sunrise/plugin.rb', line 14

def module_name
  @module_name ||= @name.singularize.camelize.to_sym
end

#titleObject



26
27
28
# File 'lib/sunrise/plugin.rb', line 26

def title
  I18n.t(@name, :scope => [:manage, :plugins])
end