Class: GitCommander::RSpec::PluginHelpers::MockGemfile

Inherits:
Object
  • Object
show all
Defined in:
lib/git_commander/rspec/plugin_helpers.rb

Overview

nodoc

Constant Summary collapse

DEFAULT_GEM_SOURCE =
"https://rubygems.org"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMockGemfile

Returns a new instance of MockGemfile.



17
18
19
20
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 17

def initialize
  @gems = {}
  @source = DEFAULT_GEM_SOURCE
end

Instance Attribute Details

#gemsObject (readonly)

Returns the value of attribute gems.



15
16
17
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 15

def gems
  @gems
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 15

def options
  @options
end

Instance Method Details

#gem(name, *options) ⇒ Object



22
23
24
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 22

def gem(name, *options)
  @gems[name] = options || []
end

#gem_definition(name, *options) ⇒ Object



39
40
41
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 39

def gem_definition(name, *options)
  ["gem '#{name}'", *Array(options).map { |o| gem_option_to_s(o) }].join(", ")
end

#gem_option_to_s(option) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 43

def gem_option_to_s(option)
  return "" if option.to_s.empty?

  case option
  when Hash
    option.map { |k, v| "#{k}: '#{v}'" }
  else
    "'#{option}'"
  end
end

#gemfile_linesObject



32
33
34
35
36
37
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 32

def gemfile_lines
  [
    source,
    *@gems.map { |name, options| gem_definition(name, *options) }
  ]
end

#source(value = nil) ⇒ Object



26
27
28
29
30
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 26

def source(value = nil)
  return "source: '#{@source}'" if value.nil?

  @source = value
end