Class: Release::Gem::GemDep

Inherits:
Object
  • Object
show all
Includes:
TR::CondUtils
Defined in:
lib/release/gem/gemdep.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, opts = { }) ⇒ GemDep

Returns a new instance of GemDep.



12
13
14
15
16
17
18
19
20
# File 'lib/release/gem/gemdep.rb', line 12

def initialize(root, opts = {  })
  @root = root
  @discardColor = opts[:discardColor] || false
  @devGems = {}
  @gemConfig = {}
  @fileHistory = {}
  load_gemfile_deps
  load_gemspec_deps
end

Instance Method Details

#all_dev_gems_has_config?Boolean

transfer_gem

Returns:

  • (Boolean)


70
71
72
# File 'lib/release/gem/gemdep.rb', line 70

def all_dev_gems_has_config?
  not_configured_gem.length == 0   
end

#configure_gem(name, opts = { type: :runtime, version: "" }) ⇒ Object

Raises:



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/release/gem/gemdep.rb', line 48

def configure_gem(name, opts = { type: :runtime, version: "" })
  raise GemDepError, "Given option to configure the gem is empty" if is_empty?(opts)
  raise GemDepError, "Given option is not a hash. Hash wity keys :type and/or :version (can be empty) is expected" if not opts.is_a?(Hash)
  raise GemDepError, "Production gem type not given. Please provide the gem type via key :type (valid value is either :runtime or :dev)" if is_empty?(opts[:type])

  if @devGems.keys.include?(name.to_s) 
    @gemConfig[name.to_s] = opts
  else
    raise GemDepError, "Name '#{name}' is not in the list of development gems. Valid value including : #{@devGems.keys.join(", ")}"
  end
end

#development_gemObject



44
45
46
# File 'lib/release/gem/gemdep.rb', line 44

def development_gem
  @devGems
end

#has_development_gem?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/release/gem/gemdep.rb', line 40

def has_development_gem?
  not_empty?(@devGems)
end

#infect_gem(gem_root, name, &block) ⇒ Object



87
88
89
90
91
# File 'lib/release/gem/gemdep.rb', line 87

def infect_gem(gem_root,name, &block)
  ri = ReleaseInfector.new(gem_root, name)
  ri.infect(&block)
  ri.trigger_release_gem(&block)
end

#load_gemfile_depsObject



22
23
24
25
26
27
28
29
# File 'lib/release/gem/gemdep.rb', line 22

def load_gemfile_deps
  gdef = Bundler::Definition.build(gemfile_file, nil, {})
  gdef.dependencies.each do |d|
    if not d.source.nil? and d.source.path.to_s != "."
      @devGems[d.name] = d.source.path.to_s
    end
  end
end

#load_gemspec_depsObject



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

def load_gemspec_deps
  gs = ::Gem::Specification.load(gemspec_file)
  gs.dependencies.each do |d|
    if not d.source.nil? and d.source.path.to_s != "."
      @devGems[d.name] = d.source.path.to_s
    end
  end
end

#not_configured_gemObject



74
75
76
# File 'lib/release/gem/gemdep.rb', line 74

def not_configured_gem
  @devGems.keys.difference(@gemConfig.keys)
end

#restore_dev_gemObject



78
79
80
81
82
83
84
85
# File 'lib/release/gem/gemdep.rb', line 78

def restore_dev_gem
  Gem.logger.debug "restore_dev_gem : #{@fileHistory.inspect}"
  @fileHistory.each do |k,v|
    FileUtils.mv(k,"#{k}.prod")
    FileUtils.cp(v,k)
  end
  @fileHistory.clear
end

#transfer_gemObject



60
61
62
63
64
65
66
67
68
# File 'lib/release/gem/gemdep.rb', line 60

def transfer_gem
  if not all_dev_gems_has_config?
    raise GemDepError, "Not all gem has configuration. Gem required configuration includes: #{not_configured_gem.join(", ")}"
  end

  remove_dev_gem_from_gemfile
  add_gem_to_gemspec(@gemConfig)

end