Module: MikutterPluginManager

Defined in:
lib/mikutter_plugin_manager.rb,
lib/mikutter_plugin_manager/cli.rb,
lib/mikutter_plugin_manager/version.rb

Defined Under Namespace

Classes: CLI

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.exportObject

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



72
73
74
75
76
77
78
79
80
81
82
# 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) ⇒ Object

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



114
115
116
# 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) ⇒ Object

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

.installObject

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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) ⇒ Object

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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 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

.updateObject

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



60
61
62
63
64
65
66
67
68
# 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