Class: Gem::Release::Files::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/gem/release/files/template.rb,
lib/gem/release/files/template/context.rb

Defined Under Namespace

Classes: Context

Constant Summary collapse

FILES =
{
  '.gitignore' => '.gitignore',
  'Gemfile'    => 'Gemfile',
  'gemspec'    => '%{gem_name}.gemspec',
  'license'    => 'MIT-LICENSE.md',
  'main.rb'    => 'lib/%{gem_path}.rb',
  'version.rb' => 'lib/%{gem_path}/version.rb'
}.freeze
PATH =
File.expand_path('../..', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target, data, opts) ⇒ Template

Returns a new instance of Template.


21
22
23
24
25
26
# File 'lib/gem/release/files/template.rb', line 21

def initialize(source, target, data, opts)
  @source = source
  @target = (FILES[target] || target) % data
  @data   = data
  @opts   = opts
end

Instance Attribute Details

#dataObject

Returns the value of attribute data


19
20
21
# File 'lib/gem/release/files/template.rb', line 19

def data
  @data
end

#optsObject

Returns the value of attribute opts


19
20
21
# File 'lib/gem/release/files/template.rb', line 19

def opts
  @opts
end

#sourceObject

Returns the value of attribute source


19
20
21
# File 'lib/gem/release/files/template.rb', line 19

def source
  @source
end

#targetObject

Returns the value of attribute target


19
20
21
# File 'lib/gem/release/files/template.rb', line 19

def target
  @target
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/gem/release/files/template.rb', line 43

def exists?
  File.exist?(target.to_s)
end

#filenameObject


30
31
32
# File 'lib/gem/release/files/template.rb', line 30

def filename
  File.basename(target)
end

#writeObject


34
35
36
37
38
39
40
41
# File 'lib/gem/release/files/template.rb', line 34

def write
  return false if exists?

  FileUtils.mkdir_p(File.dirname(target))
  File.write(target, render)
  FileUtils.chmod('+x', target) if opts[:executable]
  true
end