Class: Dato::Dump::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/dato/dump/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path, api_token) ⇒ Runner

Returns a new instance of Runner.



11
12
13
14
# File 'lib/dato/dump/runner.rb', line 11

def initialize(config_path, api_token)
  @config_path = config_path
  @api_token = api_token
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



9
10
11
# File 'lib/dato/dump/runner.rb', line 9

def api_token
  @api_token
end

#config_pathObject (readonly)

Returns the value of attribute config_path.



9
10
11
# File 'lib/dato/dump/runner.rb', line 9

def config_path
  @config_path
end

Instance Method Details

#clientObject



36
37
38
39
40
41
42
43
44
# File 'lib/dato/dump/runner.rb', line 36

def client
  @client ||= Dato::Site::Client.new(
    api_token,
    extra_headers: {
      'X-Reason' => 'dump',
      'X-SSG' => generator
    }
  )
end

#generatorObject



46
47
48
# File 'lib/dato/dump/runner.rb', line 46

def generator
  SsgDetector.new(Dir.pwd).detect
end

#operationObject



28
29
30
# File 'lib/dato/dump/runner.rb', line 28

def operation
  @operation ||= Operation::Root.new(Dir.pwd)
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dato/dump/runner.rb', line 16

def run
  site.load

  Dsl::Root.new(
    File.read(config_path),
    site.items_repo,
    operation
  )

  operation.perform
end

#siteObject



32
33
34
# File 'lib/dato/dump/runner.rb', line 32

def site
  @site ||= Dato::Local::Site.new(client)
end