Class: Locomotive::Mounter::Reader::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/mounter/reader/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/reader/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/reader/runner.rb', line 7

def kind
  @kind
end

#mounting_pointObject

Returns the value of attribute mounting_point.



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

def mounting_point
  @mounting_point
end

#parametersObject

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

Instance Method Details

#prepareObject

Before building the mounting point. Can be defined by reader runners



56
57
# File 'lib/locomotive/mounter/reader/runner.rb', line 56

def prepare
end

#readersArray

Ordered list of atomic readers

Returns:

  • (Array)

    List of classes

Raises:



63
64
65
# File 'lib/locomotive/mounter/reader/runner.rb', line 63

def readers
  raise Locomotive::Mounter::ImplementationIsMissingException.new('readers are missing')
end

#reload(*list) ⇒ Object

Reload with the same origin parameters a part of a site from a list of resources each described by a simple name (site, pages, …etc) taken from the corresponding reader class name.

Parameters:

  • list (Array/ String)

    An array of resource(s) or just the resource



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/locomotive/mounter/reader/runner.rb', line 38

def reload(*list)
  Locomotive::Mounter.with_locale(self.mounting_point.default_locale) do
    [*list].flatten.each do |name|
      reader_name = "#{name.to_s.camelize}Reader"

      reader = self.readers.detect do |_reader|
        _reader.name.demodulize == reader_name
      end

      if reader
        self.mounting_point.register_resource(name, reader.new(self).read)
      end
    end
  end
end

#run!(parameters = {}) ⇒ Object

Read the content of a site (pages, snippets, …etc) and create the corresponding mounting point.

Parameters:

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

    The parameters.

Returns:

  • (Object)

    The mounting point object storing all the information about the site



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

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

  self.prepare

  self.build_mounting_point
end