Class: Greg::GemfileTemplate

Inherits:
FileTemplate show all
Defined in:
lib/greg/templates/gemfile_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FileTemplate

#create!, #msg

Methods inherited from DefaultTemplate

#app_class_name, #app_name

Constructor Details

#initialize(*gems) ⇒ GemfileTemplate

Returns a new instance of GemfileTemplate.



5
6
7
# File 'lib/greg/templates/gemfile_template.rb', line 5

def initialize(*gems)
  @gems = gems
end

Instance Attribute Details

#gemsObject (readonly)

Returns the value of attribute gems.



3
4
5
# File 'lib/greg/templates/gemfile_template.rb', line 3

def gems
  @gems
end

Instance Method Details

#contentsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/greg/templates/gemfile_template.rb', line 13

def contents
  @contents = []
  @contents << 'source "https://rubygems.org"'
  @contents << nil

  @gems.each do |gem|
    if gem.is_a?(Hash)
      gem_name, gem_options = gem.first
      r = []
      r << "gem \"#{gem_name}\""
      gem_options.each do |key, value|
        r << "#{key.to_sym}: \"#{value.to_s}\""
      end
      @contents << r.join(", ")
    else
      @contents << "gem \"#{gem}\""
    end
  end

  @contents.join("\n")
end

#destinationObject



9
10
11
# File 'lib/greg/templates/gemfile_template.rb', line 9

def destination
  "Gemfile"
end