Class: Configature::Stamper
- Inherits:
-
Object
- Object
- Configature::Stamper
- Defined in:
- lib/configature/stamper.rb
Instance Method Summary collapse
- #apply!(force: false) ⇒ Object
- #clean! ⇒ Object
- #examples ⇒ Object
-
#initialize(dir) ⇒ Stamper
constructor
A new instance of Stamper.
Constructor Details
#initialize(dir) ⇒ Stamper
Returns a new instance of Stamper.
2 3 4 |
# File 'lib/configature/stamper.rb', line 2 def initialize(dir) @dir = dir end |
Instance Method Details
#apply!(force: false) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/configature/stamper.rb', line 30 def apply!(force: false) self.examples.each do |source, target| if (!force and File.exist?(target)) yield( source, target, created: false, existing: true, config_required: !!File.read(target).match(/__[A-Z\-\_]+__/) ) if (block_given?) else FileUtils.copy(source, target) yield( source, target, created: true, existing: false, config_required: !!File.read(target).match(/__[A-Z\-\_]+__/) ) if (block_given?) end end end |
#clean! ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/configature/stamper.rb', line 20 def clean! self.examples.each do |_source, target| if (File.exist?(target)) File.unlink(target) yield(target) if (block_given?) end end end |
#examples ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/configature/stamper.rb', line 6 def examples map = Dir.glob(File.('*.example', @dir)).map do |source| [ source, source.delete_suffix('.example') ] end.to_h if (block_given?) map.each do |k,v| yield(k, v) end end map end |