Class: Locomotive::Mounter::Writer::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/mounter/writer/runner.rb

Direct Known Subclasses

Api::Runner, FileSystem::Runner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
# File 'lib/locomotive/mounter/writer/runner.rb', line 9

def initialize(kind)
  self.kind = kind

  # avoid to load all the ruby files at the startup, only when we need it
  base_dir = File.join(File.dirname(__FILE__), kind.to_s)
  require File.join(base_dir, 'base.rb')
  Dir[File.join(base_dir, '*.rb')].each { |lib| require lib }
end

Instance Attribute Details

#kindObject

Returns the value of attribute kind.



7
8
9
# File 'lib/locomotive/mounter/writer/runner.rb', line 7

def kind
  @kind
end

#mounting_pointObject

Returns the value of attribute mounting_point.



7
8
9
# File 'lib/locomotive/mounter/writer/runner.rb', line 7

def mounting_point
  @mounting_point
end

#parametersObject

Returns the value of attribute parameters.



7
8
9
# File 'lib/locomotive/mounter/writer/runner.rb', line 7

def parameters
  @parameters
end

Instance Method Details

#force?Boolean

By setting the force option to true, some resources (site, content assets, …etc) may overide the content of the remote engine during the push operation. By default, its value is false.

Returns:

  • (Boolean)

    True if the force option has been set to true



65
66
67
# File 'lib/locomotive/mounter/writer/runner.rb', line 65

def force?
  self.parameters[:force] || false
end

#prepareObject

Before starting to write anything Can be defined by writer runners



34
35
# File 'lib/locomotive/mounter/writer/runner.rb', line 34

def prepare
end

#run!(parameters = {}) ⇒ Object

Write the data of a mounting point instance to a target folder

Parameters:

  • parameters (Hash) (defaults to: {})

    The parameters. It should contain the mounting_point and target_path keys.



22
23
24
25
26
27
28
29
30
# File 'lib/locomotive/mounter/writer/runner.rb', line 22

def run!(parameters = {})
  self.parameters = parameters.symbolize_keys

  self.mounting_point = self.parameters.delete(:mounting_point)

  self.prepare

  self.write_all
end

#write_allObject

Execute all the writers



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/locomotive/mounter/writer/runner.rb', line 46

def write_all
  only = parameters[:only].try(:map) do |name|
    "#{name}_writer".camelize
  end.try(:insert, 0, 'SiteWriter')

  self.writers.each do |klass|
    next if only && !only.include?(klass.name.demodulize)
    writer = klass.new(self.mounting_point, self)
    writer.prepare
    writer.write
  end
end

#writersArray

List of all the writers

Returns:

  • (Array)

    List of the writer classes

Raises:



41
42
43
# File 'lib/locomotive/mounter/writer/runner.rb', line 41

def writers
  raise Locomotive::Mounter::ImplementationIsMissingException.new("[#{self.kind}] Writers are missing")
end