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.



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
106
107
108
109
110
# File 'lib/auto/plugins.rb', line 81

def initialize(directory)
  name = File.basename(directory)
  name = name.split('-')
  
  if name.include?('auto')
    @name = name[name.index('auto') + 1]
  else
    @name = nil
  end
  
  # ~/.auto/auto-plugin/lib/plugin.rb
  @library = "#{directory}/lib/auto/#{@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.



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

def library
  @library
end

#moduleObject (readonly)

Returns the value of attribute module.



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

def module
  @module
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#tasksObject (readonly)

Returns the value of attribute tasks.



78
79
80
# File 'lib/auto/plugins.rb', line 78

def tasks
  @tasks
end