Class: Roject::FileMaker
- Inherits:
-
Object
- Object
- Roject::FileMaker
- Defined in:
- lib/makers.rb
Overview
Creates files according to the given credentials
Author: Anshul Kharbanda Created: 7 - 21 - 2016
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Read extension, directory, and template.
-
#extension ⇒ Object
readonly
Read extension, directory, and template.
-
#template ⇒ Object
readonly
Read extension, directory, and template.
Instance Method Summary collapse
-
#initialize(project, hash) ⇒ FileMaker
constructor
Initializes a FileMaker from the given hash.
-
#make(project, args) ⇒ Object
Creates a file of the filetype with the given args.
Constructor Details
#initialize(project, hash) ⇒ FileMaker
Initializes a FileMaker from the given hash
Parameter: hash - the hash to parse
53 54 55 56 57 |
# File 'lib/makers.rb', line 53 def initialize project, hash @path = General::GTemplate.new hash[:path] @template = General::GIO.load "#{project.config[:directory][:templates]}/#{hash[:template]}" @extension = hash[:extension] end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Read extension, directory, and template
48 49 50 |
# File 'lib/makers.rb', line 48 def directory @directory end |
#extension ⇒ Object (readonly)
Read extension, directory, and template
48 49 50 |
# File 'lib/makers.rb', line 48 def extension @extension end |
#template ⇒ Object (readonly)
Read extension, directory, and template
48 49 50 |
# File 'lib/makers.rb', line 48 def template @template end |
Instance Method Details
#make(project, args) ⇒ Object
Creates a file of the filetype with the given args
Parameter: project - the project running the task Parameter: args - the args being used to create the file
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/makers.rb', line 63 def make project, args # merge args with project args.merge! project.config # Get path path = "#{@path.apply(args)}.#{@extension}" # Create directory dir = File.dirname(path) FileUtils.mkdir_p dir unless Dir.exist? dir # Write template to path @template.write(path, args) end |