Class: Corundum::CLI::Skelfiles::Skelfile

Inherits:
Object
  • Object
show all
Defined in:
lib/corundum/cli/skelfiles.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#excludeObject (readonly)

Returns the value of attribute exclude.



13
14
15
# File 'lib/corundum/cli/skelfiles.rb', line 13

def exclude
  @exclude
end

#messageObject (readonly)

Returns the value of attribute message.



13
14
15
# File 'lib/corundum/cli/skelfiles.rb', line 13

def message
  @message
end

#sourceObject (readonly)

Returns the value of attribute source.



13
14
15
# File 'lib/corundum/cli/skelfiles.rb', line 13

def source
  @source
end

#targetObject (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

#templatesObject



15
16
17
# File 'lib/corundum/cli/skelfiles.rb', line 15

def templates
  Corundum.configuration_store.valise.templates("skel-files")
end