Class: Auto::Plugins::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/auto/plugins.rb

Overview

Stores a plugin’s name, library, and tasks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ Plugin

Assigns attributes using a plugin directory path.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/auto/plugins.rb', line 79

def initialize(directory)
  name = File.basename(directory)
  name = name.split('-')
  
  return nil unless name.include?('auto')
  @name = name[name.index('auto') + 1]
  
  # ~/.auto/auto-plugin/lib/plugin.rb
  @library = "#{directory}/lib/#{@name}.rb"
  @library = nil unless File.exists?(@library)
  
  # Auto::Plugin
  if @library
    @module = File.basename(@library, '.rb').camelize
  else
    @module = nil
  end
  
  # ~/.auto/auto-plugin/auto/task.rb
  @tasks = Dir["#{directory}/.auto/**/*.rb"].sort.collect do |path|
    relative = path.gsub("#{directory}/.auto/", '')
    {
      :name => relative[0..-4].split('/').join(':').downcase,
      :path => path
    }
  end
end

Instance Attribute Details

#libraryObject (readonly)

Returns the value of attribute library.



74
75
76
# File 'lib/auto/plugins.rb', line 74

def library
  @library
end

#moduleObject (readonly)

Returns the value of attribute module.



75
76
77
# File 'lib/auto/plugins.rb', line 75

def module
  @module
end

#nameObject (readonly)

Returns the value of attribute name.



73
74
75
# File 'lib/auto/plugins.rb', line 73

def name
  @name
end

#tasksObject (readonly)

Returns the value of attribute tasks.



76
77
78
# File 'lib/auto/plugins.rb', line 76

def tasks
  @tasks
end