Class: DirectoryTemplate::ProcessData

Inherits:
Object
  • Object
show all
Defined in:
lib/directory_template/process_data.rb

Overview

ProcessData is the value that gets passed to processors. The processor must mutate it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory_template, path, content, env) ⇒ ProcessData

A content of nil means this is a directory

Parameters:

  • env (Hash)

    A hash with additional information, used to parametrize and preprocess the template. @options env [Hash<Symbol,String>] :variables

    Variables used for both, path- and filecontent processing.
    

    @options env [Hash<Symbol,String>] :path_variables

    Variables only used for path-processing.
    

    @options env [Hash<Symbol,String>] :content_variables

    Variables only used for filecontent processing.
    


44
45
46
47
48
49
50
51
# File 'lib/directory_template/process_data.rb', line 44

def initialize(directory_template, path, content, env)
  @directory_template = directory_template
  @content            = content
  @variables          = env[:variables] || {}
  @path_variables     = @variables.merge(env[:path_variables] || {})
  @content_variables  = @variables.merge(env[:content_variables] || {})
  self.path           = path
end

Instance Attribute Details

#contentObject

The file-content, as it is in the current stage of processing (nil for directories).



23
24
25
# File 'lib/directory_template/process_data.rb', line 23

def content
  @content
end

#content_variablesObject (readonly)

Variables to be used for filecontent preprocessing



29
30
31
# File 'lib/directory_template/process_data.rb', line 29

def content_variables
  @content_variables
end

#directoryObject (readonly)

The directory, as it is in the current stage of processing.



17
18
19
# File 'lib/directory_template/process_data.rb', line 17

def directory
  @directory
end

#directory_templateObject (readonly)

A reference to the DirectoryTemplate of which this file/directory is part of



8
9
10
# File 'lib/directory_template/process_data.rb', line 8

def directory_template
  @directory_template
end

#filenameObject (readonly)

The filename, as it is in the current stage of processing.



14
15
16
# File 'lib/directory_template/process_data.rb', line 14

def filename
  @filename
end

#pathObject

The path as it is in the current stage of processing.



11
12
13
# File 'lib/directory_template/process_data.rb', line 11

def path
  @path
end

#path_variablesObject (readonly)

Variables to be used for path preprocessing



26
27
28
# File 'lib/directory_template/process_data.rb', line 26

def path_variables
  @path_variables
end

#suffixObject (readonly)

The suffix, as it is in the current stage of processing.



20
21
22
# File 'lib/directory_template/process_data.rb', line 20

def suffix
  @suffix
end

#variablesObject (readonly)

Variables to be used for both, path- and filecontent preprocessing



32
33
34
# File 'lib/directory_template/process_data.rb', line 32

def variables
  @variables
end

Instance Method Details

#===(processor) ⇒ Object

Whether the processor is suitable for the given ProcessData. Simply delegates the job to the Processor.



57
58
59
# File 'lib/directory_template/process_data.rb', line 57

def ===(processor)
  processor === self
end

#chomp_suffix!Object

Removes the current suffix. E.g. “foo/bar.baz.quuz” would be “foo/bar.baz” after the operation.



90
91
92
# File 'lib/directory_template/process_data.rb', line 90

def chomp_suffix!
  self.path   = @path.chomp(@suffix)
end

#directory?Boolean

Returns Whether the item is a directory. The alternative is, that it is a file.

Returns:

  • (Boolean)

    Whether the item is a directory. The alternative is, that it is a file.

See Also:



73
74
75
# File 'lib/directory_template/process_data.rb', line 73

def directory?
  !@content
end

#file?Boolean

Returns Whether the item is a file. The alternative is, that it is a directory.

Returns:

  • (Boolean)

    Whether the item is a file. The alternative is, that it is a directory.

See Also:



65
66
67
# File 'lib/directory_template/process_data.rb', line 65

def file?
  !!@content
end