Class: Senju::Projects

Inherits:
Object
  • Object
show all
Defined in:
lib/senju/projects.rb

Constant Summary collapse

PATH =
Dir.home + '/.senju/projects'

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



21
22
23
# File 'lib/senju/projects.rb', line 21

def self.[](name)
  data[name] || raise("Unknown project \"#{name}\".")
end

.[]=(name, table) ⇒ Object



25
26
27
# File 'lib/senju/projects.rb', line 25

def self.[]=(name, table)
  data[name] = table
end

.add_interactive(name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/senju/projects.rb', line 29

def self.add_interactive(name)
  print "Repository type [github, gitlab, trello]: "

  type = STDIN.gets.chomp
  case type
  when "github", "gitlab"
    print "Repository path (team/repository): "
    repo = STDIN.gets.chomp
  when "trello"
    print "board id (like aBcDeF1234): "
    repo = STDIN.gets.chomp
  end

  self[name] = { "repo" => repo, "type" => type }
  write

  print "Senju project add successfly.\n".colorize(:green)
end

.dataObject



17
18
19
# File 'lib/senju/projects.rb', line 17

def self.data
  self.load
end

.loadObject



5
6
7
8
9
10
11
# File 'lib/senju/projects.rb', line 5

def self.load
  if File.exist? PATH
    @data = YAML.load_file(PATH)
  else
    @data = {}
  end
end

.writeObject



13
14
15
# File 'lib/senju/projects.rb', line 13

def self.write
  YAML.dump(@data, File.open(PATH, 'w'))
end