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.


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

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


16
17
18
# File 'lib/gem/release/files/template.rb', line 16

def data
  @data
end

#optsObject

Returns the value of attribute opts


16
17
18
# File 'lib/gem/release/files/template.rb', line 16

def opts
  @opts
end

#sourceObject

Returns the value of attribute source


16
17
18
# File 'lib/gem/release/files/template.rb', line 16

def source
  @source
end

#targetObject

Returns the value of attribute target


16
17
18
# File 'lib/gem/release/files/template.rb', line 16

def target
  @target
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/gem/release/files/template.rb', line 39

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

#filenameObject


27
28
29
# File 'lib/gem/release/files/template.rb', line 27

def filename
  File.basename(target)
end

#writeObject


31
32
33
34
35
36
37
# File 'lib/gem/release/files/template.rb', line 31

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