Class: Copypasta::ContentsDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/copypasta/contents_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents, directory) ⇒ ContentsDSL

Returns a new instance of ContentsDSL.



6
7
8
9
10
11
12
13
14
# File 'lib/copypasta/contents_dsl.rb', line 6

def initialize(contents, directory)
  raise "contents must be a Copypasta::Contents" \
    unless contents.is_a?(Copypasta::Contents)

  raise "#{directory} doesn't exist." unless Dir.exist?(directory)

  @contents = contents
  @directory = directory
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



3
4
5
# File 'lib/copypasta/contents_dsl.rb', line 3

def contents
  @contents
end

#directoryObject (readonly)

Returns the value of attribute directory.



4
5
6
# File 'lib/copypasta/contents_dsl.rb', line 4

def directory
  @directory
end

Instance Method Details

#copy(filename, source: nil, only_if: nil) ⇒ Object



20
21
22
# File 'lib/copypasta/contents_dsl.rb', line 20

def copy(filename, source: nil, only_if: nil)
  contents.entries << Copypasta::Entry::Copy.new(filename, directory: @directory, source: source, only_if: only_if).freeze
end

#create_even_if_empty!Object



16
17
18
# File 'lib/copypasta/contents_dsl.rb', line 16

def create_even_if_empty!
  contents.force_create = true
end

#download(filename, source: nil, only_if: nil) ⇒ Object



28
29
30
# File 'lib/copypasta/contents_dsl.rb', line 28

def download(filename, source: nil, only_if: nil)
  contents.entries << Copypasta::Entry::Download.new(filename, source: source, only_if: only_if).freeze
end

#erb(filename, source: nil, locals: {}, only_if: nil) ⇒ Object



24
25
26
# File 'lib/copypasta/contents_dsl.rb', line 24

def erb(filename, source: nil, locals: {}, only_if: nil)
  contents.entries << Copypasta::Entry::ERB.new(filename, directory: @directory, source: source, locals: locals, only_if: only_if).freeze
end

#literal(filename, data:, only_if: nil) ⇒ Object



32
33
34
# File 'lib/copypasta/contents_dsl.rb', line 32

def literal(filename, data:, only_if: nil)
  contents.entries << Copypasta::Entry::Literal.new(filename, data: data, only_if: only_if).freeze
end