Class: Mygithub::CliCore

Inherits:
Object
  • Object
show all
Defined in:
lib/mygithub/cli_core.rb

Instance Method Summary collapse

Constructor Details

#initializeCliCore

Returns a new instance of CliCore.



17
18
19
20
21
# File 'lib/mygithub/cli_core.rb', line 17

def initialize
  @settings = Settings.new
  @github   = GithubAccessor.new @settings.username, @settings.token
  @milk     = MilkodeAccessor.new Settings.default_database
end

Instance Method Details

#init(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/mygithub/cli_core.rb', line 23

def init(options)
  if (@settings.empty?)
    @settings.save unless options[:no_save]
    puts "Create -> #{Settings.default_filename}"
    puts "Please edit YAML settings!"
  else
    puts "Already exists '#{Settings.default_filename}'."
    puts "Please edit YAML settings!"
  end
end

#update(args, options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mygithub/cli_core.rb', line 34

def update(args, options)
  # initialize
  @milk.init
  @milk.create_milkweb_yaml(@github.avatar_url)

  # Get repo_names
  if args.empty?
    names = @github.repo_names.map {|r| r.sub(@settings.username + '/', "")}
  else
    names = args
  end

  # update or add
  add_repos    = []
  update_repos = []

  names.each do |name|
    next if name.match("/")
    
    unless @milk.exist? name
      add_repos << "git://github.com/#{@settings.username}/#{name}.git"
    else
      update_repos << name
    end
  end

  @milk.add add_repos       unless add_repos.empty?
  @milk.update update_repos unless update_repos.empty?
end

#web(options) ⇒ Object



64
65
66
# File 'lib/mygithub/cli_core.rb', line 64

def web(options)
  @milk.web(options)
end