Class: NeocitiesRed::Services::SiteExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/neocities_red/services/site_exporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, sitename, data, app_config_path) ⇒ SiteExporter

Returns a new instance of SiteExporter.



11
12
13
14
15
16
17
# File 'lib/neocities_red/services/site_exporter.rb', line 11

def initialize(client, sitename, data, app_config_path)
  @client = client
  @sitename = sitename
  @data = data
  @app_config_path = app_config_path
  @pastel = Pastel.new(eachline: "\n")
end

Instance Attribute Details

#app_config_pathObject

Returns the value of attribute app_config_path.



9
10
11
# File 'lib/neocities_red/services/site_exporter.rb', line 9

def app_config_path
  @app_config_path
end

#clientObject

Returns the value of attribute client.



9
10
11
# File 'lib/neocities_red/services/site_exporter.rb', line 9

def client
  @client
end

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/neocities_red/services/site_exporter.rb', line 9

def data
  @data
end

#sitenameObject

Returns the value of attribute sitename.



9
10
11
# File 'lib/neocities_red/services/site_exporter.rb', line 9

def sitename
  @sitename
end

Instance Method Details

#export(quiet: false, last_pull_time: nil, last_pull_loc: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/neocities_red/services/site_exporter.rb', line 19

def export(quiet: false, last_pull_time: nil, last_pull_loc: nil)
  if quiet
    Whirly.start spinner: ["😺", "😸", "😹", "😻", "😼", "😽", "🙀", "😿", "😾"],
                 status: "Retrieving files for #{@pastel.bold @sitename}"
  end

  @client.pull(@sitename, last_pull_time, last_pull_loc, quiet: quiet)

  # write last pull data to file (not necessarily the best way to do this, but better than cloning every time)
  data["LAST_PULL"] = {
    time: Time.now,
    loc: Dir.pwd
  }

  File.write(app_config_path, data.to_json)
rescue StandardError => e
  e
ensure
  Whirly.stop if quiet
end