Module: Projectionist::Projects

Defined in:
lib/projectionist/projects.rb,
lib/projectionist/projects/version.rb

Constant Summary collapse

INDEX_ROOT =
"jeremywrowe.github.io"
DOWNLOAD_DIRECTORY =
File.join(ENV["HOME"], ".projection-projects")
VERSION =
"0.1.5"

Class Method Summary collapse

Class Method Details

.download(project:, confirm: true, stdin: -> { gets }) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/projectionist/projects.rb', line 23

def self.download(project:, confirm: true, stdin: -> { gets })
  normalized_project = "#{project}.projections.json"
  destination_file   = File.join(DOWNLOAD_DIRECTORY, normalized_project)

  if confirm && File.exist?(destination_file)
    print "Overwrite existing file? (y/N) "
    return unless stdin.call.strip.downcase == "y"
  end
  
  json_contents = Net::HTTP.get INDEX_ROOT, "/projectionist-projects-files/downloads/#{normalized_project}"
  File.open(destination_file, "w") do |file|
    file.write json_contents
  end
rescue SocketError
  throw :server_unavailable
end

.fetchObject



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

def self.fetch
  csv_contents = Net::HTTP.get INDEX_ROOT, "/projectionist-projects-files/downloads/index.csv"
  CSV.new(csv_contents, headers: true, header_converters: :symbol)
    .map(&:to_hash)
rescue SocketError
  throw :server_unavailable
end