Module: Pluto

Defined in:
lib/pluto/tasks.rb

Class Method Summary collapse

Class Method Details

.fetch_config_for(key) ⇒ Object

todo/fix: move to pluto-update for (re)use !!!!



26
27
28
29
30
31
32
33
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
63
64
65
66
67
68
69
70
71
# File 'lib/pluto/tasks.rb', line 26

def self.fetch_config_for( key )
  ###
  ## todo:
  ##  move into a method for (re)use
  puts "trying to fetch pluto.index.ini shortcut planet registry..."

  ## Note: Pluto includes its own Fetcher, thus, use ::Fetcher!!
  worker = ::Fetcher::Worker.new
  res = worker.get_response( 'https://raw.githubusercontent.com/feedreader/planets/master/pluto.index.ini' )
  if res.code != '200'
    puts "sorry; failed to fetch pluto.index - HTTP #{res.code} - #{res.message}"
    exit 1
  end

  ###
  # Note: Net::HTTP will NOT set encoding UTF-8 etc.
  #  will be set to ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
  #  thus, set/force encoding to utf-8
  index_txt = res.body.dup.to_s
  index_txt = index_txt.force_encoding( Encoding::UTF_8 )

  shortcuts = INI.load( index_txt )
  pp shortcuts

  shortcut = shortcuts[key]
  if shortcut.nil?
    puts "sorry; no planet shortcut found for key >#{key}<"
    exit 1
  end

  res = worker.get_response( shortcut['source'] )
  if res.code != '200'
    puts "sorry; failed to fetch planet config for >#{key}< - HTTP #{res.code} - #{res.message}"
    exit 1
  end

  ###
  # Note: Net::HTTP will NOT set encoding UTF-8 etc.
  #  will be set to ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
  #  thus, set/force encoding to utf-8
  config_txt = res.body.dup.to_s
  config_txt = config_txt.force_encoding( Encoding::UTF_8 )

  config = INI.load( config_txt )
  config
end

.load_tasksObject



15
16
17
18
19
20
21
# File 'lib/pluto/tasks.rb', line 15

def self.load_tasks
  # load all builtin Rake tasks (from tasks/*rake)
  load 'pluto/tasks/environment.rake'
  load 'pluto/tasks/setup.rake'
  load 'pluto/tasks/stats.rake'
  load 'pluto/tasks/update.rake'
end