Class: Copypasta::ContentsDSL
- Inherits:
-
Object
- Object
- Copypasta::ContentsDSL
- Defined in:
- lib/copypasta/contents_dsl.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
- #copy(filename, source: nil, only_if: nil) ⇒ Object
- #create_even_if_empty! ⇒ Object
- #download(filename, source: nil, only_if: nil) ⇒ Object
- #erb(filename, source: nil, locals: {}, only_if: nil) ⇒ Object
-
#initialize(contents, directory) ⇒ ContentsDSL
constructor
A new instance of ContentsDSL.
- #literal(filename, data:, only_if: nil) ⇒ Object
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
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
3 4 5 |
# File 'lib/copypasta/contents_dsl.rb', line 3 def contents @contents end |
#directory ⇒ Object (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 |