Class: GitCommander::RSpec::PluginHelpers::MockGemfile
- Inherits:
-
Object
- Object
- GitCommander::RSpec::PluginHelpers::MockGemfile
- Defined in:
- lib/git_commander/rspec/plugin_helpers.rb
Overview
nodoc
Constant Summary collapse
- DEFAULT_GEM_SOURCE =
"https://rubygems.org"
Instance Attribute Summary collapse
-
#gems ⇒ Object
readonly
Returns the value of attribute gems.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #gem(name, *options) ⇒ Object
- #gem_definition(name, *options) ⇒ Object
- #gem_option_to_s(option) ⇒ Object
- #gemfile_lines ⇒ Object
-
#initialize ⇒ MockGemfile
constructor
A new instance of MockGemfile.
- #source(value = nil) ⇒ Object
Constructor Details
#initialize ⇒ MockGemfile
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
#gems ⇒ Object (readonly)
Returns the value of attribute gems.
15 16 17 |
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 15 def gems @gems end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 15 def end |
Instance Method Details
#gem(name, *options) ⇒ Object
22 23 24 |
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 22 def gem(name, *) @gems[name] = || [] end |
#gem_definition(name, *options) ⇒ Object
39 40 41 |
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 39 def gem_definition(name, *) ["gem '#{name}'", *Array().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_lines ⇒ Object
32 33 34 35 36 37 |
# File 'lib/git_commander/rspec/plugin_helpers.rb', line 32 def gemfile_lines [ source, *@gems.map { |name, | gem_definition(name, *) } ] 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 |