Class: Canpe::RepositoryOperation
- Inherits:
-
Object
- Object
- Canpe::RepositoryOperation
- Includes:
- FileManipulation
- Defined in:
- lib/canpe/repository_operation.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #copy_evaluated_file(path) ⇒ Object
- #create_evaluated_directory(path) ⇒ Object
- #delete_file(path) ⇒ Object
- #generate_file(path) ⇒ Object
-
#initialize(repository) ⇒ RepositoryOperation
constructor
A new instance of RepositoryOperation.
- #prepare_operation(options = {}) ⇒ Object
Methods included from FileManipulation
#copy_file, #create_directory, #remove_file
Constructor Details
#initialize(repository) ⇒ RepositoryOperation
Returns a new instance of RepositoryOperation.
15 16 17 18 19 |
# File 'lib/canpe/repository_operation.rb', line 15 def initialize(repository) @repository = repository @renderer = TemplateRenderer.new(self) @context = RepositoryOperationContext.new(self) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
13 14 15 |
# File 'lib/canpe/repository_operation.rb', line 13 def context @context end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
13 14 15 |
# File 'lib/canpe/repository_operation.rb', line 13 def renderer @renderer end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
13 14 15 |
# File 'lib/canpe/repository_operation.rb', line 13 def repository @repository end |
Instance Method Details
#copy_evaluated_file(path) ⇒ Object
40 41 42 43 |
# File 'lib/canpe/repository_operation.rb', line 40 def copy_evaluated_file(path) template_file = renderer.render_file(context.source_file_path(path)) copy_file(template_file.path, context.destination_file_path(path)) end |
#create_evaluated_directory(path) ⇒ Object
34 35 36 37 38 |
# File 'lib/canpe/repository_operation.rb', line 34 def create_evaluated_directory(path) path = renderer.render_string(path) url = File.join(context.destination_root, path) create_directory(url) end |
#delete_file(path) ⇒ Object
45 46 47 |
# File 'lib/canpe/repository_operation.rb', line 45 def delete_file(path) super context.destination_file_path(path) end |
#generate_file(path) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/canpe/repository_operation.rb', line 26 def generate_file(path) if File.directory?(context.source_file_path(path)) create_evaluated_directory(path) else copy_evaluated_file(path) end end |
#prepare_operation(options = {}) ⇒ Object
21 22 23 24 |
# File 'lib/canpe/repository_operation.rb', line 21 def prepare_operation( = {}) context.prepare() renderer.prepare() end |