Class: Corundum::CLI::Skelfiles::Skelfile
- Inherits:
-
Object
- Object
- Corundum::CLI::Skelfiles::Skelfile
- Defined in:
- lib/corundum/cli/skelfiles.rb
Instance Attribute Summary collapse
-
#exclude ⇒ Object
readonly
Returns the value of attribute exclude.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #create!(scope) ⇒ Object
-
#initialize(source, target, exclude) ⇒ Skelfile
constructor
A new instance of Skelfile.
- #templates ⇒ Object
Constructor Details
#initialize(source, target, exclude) ⇒ Skelfile
Returns a new instance of Skelfile.
9 10 11 12 |
# File 'lib/corundum/cli/skelfiles.rb', line 9 def initialize(source, target, exclude) @source, @target, @exclude = source, target, exclude @message = "No attempt to create yet" end |
Instance Attribute Details
#exclude ⇒ Object (readonly)
Returns the value of attribute exclude.
13 14 15 |
# File 'lib/corundum/cli/skelfiles.rb', line 13 def exclude @exclude end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
13 14 15 |
# File 'lib/corundum/cli/skelfiles.rb', line 13 def @message end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
13 14 15 |
# File 'lib/corundum/cli/skelfiles.rb', line 13 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
13 14 15 |
# File 'lib/corundum/cli/skelfiles.rb', line 13 def target @target end |
Instance Method Details
#create!(scope) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/corundum/cli/skelfiles.rb', line 19 def create!(scope) unless (found = exclude.map{|pattern| Dir.glob(pattern)}.flatten).empty? @message = "Refusing to clobber existing '#{found.first}'" else File::open(target, "w") do |file| contents = templates.contents(source) case contents when Tilt::Template file.write(contents.render(scope, {})) else file.write(contents) end end @message = "Created #{target}" end end |
#templates ⇒ Object
15 16 17 |
# File 'lib/corundum/cli/skelfiles.rb', line 15 def templates Corundum.configuration_store.valise.templates("skel-files") end |