Skip to content

Commit 61195df

Browse files
authored
Improve error handling (#113)
* Improbe error handling * update version * Improve error handling * Update gemfile version
1 parent 2dea572 commit 61195df

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

lib/generators/templates/common/gemfile.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ gem 'rubocop'
2929
<%- if rspec? -%>
3030
gem 'rubocop-rspec'
3131
<%- end -%>
32-
gem 'ruby_raider', '~> 1.0.1'
32+
gem 'ruby_raider', '~> 1.0.4'
3333
<%= ERB.new(File.read(File.expand_path('./partials/automation_gems.tt', __dir__))).result(binding).strip! %>

lib/generators/templates/common/partials/automation_gems.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gem 'selenium-webdriver'
44
gem 'watir'
55
<% when selenium_based? %>
66
gem 'selenium-webdriver'
7-
<% else %>
7+
<% when mobile? %>
88
gem 'appium_lib'
99
gem 'appium_console'
1010
<% end %>

lib/plugin/plugin.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module RubyRaider
77
module Plugin
88
class << self
99
def add_plugin(plugin_name)
10+
return gemfile_guard unless File.exist?('Gemfile')
1011
return pp 'The plugin was not found' unless available?(plugin_name)
1112
return pp 'The plugin is already installed' if installed?(plugin_name)
1213

@@ -18,6 +19,7 @@ def add_plugin(plugin_name)
1819
end
1920

2021
def delete_plugin(plugin_name)
22+
return gemfile_guard unless File.exist?('Gemfile')
2123
return 'The plugin is not installed' unless installed_plugins.include?(plugin_name)
2224

2325
pp "Deleting #{plugin_name}..."
@@ -28,6 +30,8 @@ def delete_plugin(plugin_name)
2830
end
2931

3032
def installed_plugins
33+
return gemfile_guard unless File.exist?('Gemfile')
34+
3135
parsed_gemfile = File.readlines('Gemfile').map { |line| line.sub('gem ', '').strip.delete("'") }
3236
parsed_gemfile.select { |line| plugins.include?(line) }
3337
end
@@ -51,6 +55,8 @@ def plugins
5155
private
5256

5357
def add_plugin_to_gemfile(plugin_name)
58+
return gemfile_guard unless File.exist?('Gemfile')
59+
5460
File.open('Gemfile', 'a') do |file|
5561
file.puts "\n# Ruby Raider Plugins\n" unless comment_present?
5662
file.puts "gem '#{plugin_name}'" unless plugin_present?(plugin_name)
@@ -67,6 +73,8 @@ def last_plugin?
6773
end
6874

6975
def read_gemfile
76+
return gemfile_guard unless File.exist?('Gemfile')
77+
7078
File.readlines('Gemfile')
7179
end
7280

@@ -86,10 +94,16 @@ def remove_plugins_and_comments(plugin_name)
8694

8795
# :reek:NestedIterators { enabled: false }
8896
def update_gemfile(output_lines)
97+
return gemfile_guard unless File.exist?('Gemfile')
98+
8999
File.open('Gemfile', 'w') do |file|
90100
output_lines.each { |line| file.puts line }
91101
end
92102
end
103+
104+
def gemfile_guard
105+
pp 'There is no Gemfile, please create one to install plugins'
106+
end
93107
end
94108
end
95109
end

lib/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1
1+
1.0.4

0 commit comments

Comments
 (0)