lib/chest/plugin.rb in chest-0.1.0 vs lib/chest/plugin.rb in chest-1.0.0

- old
+ new

@@ -1,37 +1,49 @@ -class Chest::Plugin - attr_reader :path, :name, :kind +module Chest + PLUGINS_FOLDER = File.expand_path('~/Library/Containers/com.bohemiancoding.sketch3/Data/Library/Application Support/com.bohemiancoding.sketch3/Plugins') - def initialize(path) - @path = path - @name = File.basename(path) - @kind = guess_kind(path) - end + class Plugin + attr_reader :path, :name, :kind - def updatable? - @kind != :local - end + def initialize(path) + @path = path + @name = File.basename(path) + @kind = guess_kind(path) + end - def update - case @kind - when :git - update_git - else - false + def updatable? + @kind != :local end - end - def update_git - puts "Updating '#{@name}' ..." - system "cd '#{@path}' && git pull" - end + def update + case @kind + when :git + update_git + else + puts "#{@name} is kind of un-updatable plugin" + false + end + end - private + class << self + def all + Dir.glob(File.join(PLUGINS_FOLDER, '*')).collect do |path| + Dir.exist?(path) ? Plugin.new(path) : nil + end.compact + end + end - def guess_kind(path) - if Dir.exist? File.join(path, '.git') - :git - else - :local + private + def guess_kind(path) + if Dir.exist? File.join(path, '.git') + :git + else + :local + end + end + + def update_git + puts "Updating '#{@name}' ..." + system "cd '#{@path}' && git pull" end end end