module MikutterPluginManager

Constants

VERSION

Public Class Methods

export() click to toggle source

カレントディレクトリにあるすべてのプラグインを plugins.yml に書く TODO: git にないやつどうするんだ問題

# File lib/mikutter_plugin_manager.rb, line 72
def self.export
  puts 'export'
  target_yml_path = './plugins.yml'
  unless File.exist?(target_yml_path)
    puts 'plugins.yml がないよ'

    return false
  end

  return true
end
get_repo_name(repo_url) click to toggle source

リポジトリ URL の hoge.git から hoge を取る hoge.git じゃないリポジトリとかだったら死ぬやつ リポジトリの URL のみの場合に使う苦し紛れの対応

# File lib/mikutter_plugin_manager.rb, line 114
def self.get_repo_name(repo_url)
  repo_url.split('/')[-1].split('.')[0]
end
init(install_path = nil) click to toggle source

plugins.yml をカレントディレクトリに生成する

# File lib/mikutter_plugin_manager.rb, line 15
def self.init(install_path = nil)
  yml = {
    'creator' => ENV['USER'],
    'date' => Time.now.to_s,
    'plugins' => [
    ]
  }

  # ディレクトリのチェック
  unless Dir.exist?(install_path)
    puts 'ないのでディレクトリ作る'
    FileUtils.mkdir_p(install_path)
  end

  File.open(install_path + '/plugins.yml', 'w') do |f|
    YAML.dump(yml, f)
  end

  return true
end
install() click to toggle source

カレントディレクトリにある plugins.yml を読み込み、指定した場所に各プラグインを clone する

# File lib/mikutter_plugin_manager.rb, line 37
def self.install
  target_yml_path = './plugins.yml'
  unless File.exist?(target_yml_path)
    puts 'plugins.yml がないよ'

    return false
  end

  yml = YAML.load_file(target_yml_path)
  yml['plugins'].each do |plugin|
    target_name = plugin['name']
    target_repo = plugin['repo'] # 存在するものか、有効な URL かのチェックが必要
    # name なしのときは repo から取らないといけない
    target_name = self.get_repo_name(target_repo) if target_name == nil
    g = Git.clone(target_repo, target_name, :path => './')
    puts "#{target_name} cloned from #{target_repo}"
  end

  return true
end
require(target_repo, target_name = nil) click to toggle source

カレントディレクトリにプラグインを clone し、plugins.yml に追記する

# File lib/mikutter_plugin_manager.rb, line 85
def self.require(target_repo, target_name = nil)
  target_yml_path = './plugins.yml'
  unless File.exist?(target_yml_path)
    puts 'plugins.yml がないよ'

    return false
  end

  target_name = self.get_repo_name(target_repo) if target_name == nil
  g = Git.clone(target_repo, target_name, :path => './')

  yml = YAML.load_file(target_yml_path)

  new_plugin = {}
  new_plugin['name'] = target_name if target_name != nil
  new_plugin['repo'] = target_repo
  yml['plugins'].push(new_plugin)
  File.open('./plugins.yml', 'w') do |f|
    YAML.dump(yml, f)
  end

  return true
end
update() click to toggle source

インストール済みのプラグインの更新(plugins.yml に追記された未 clone のものも取得する?) TODO: lock ファイル的なものを使って制御(カレントディレクトリにあるこのファイルがあるところでのみ有効とか)

# File lib/mikutter_plugin_manager.rb, line 60
def self.update
  puts 'update'
  target_yml_path = './plugins.yml'
  unless File.exist?(target_yml_path)
    puts 'plugins.yml がないよ'

    return false
  end
end