Skip to content

Commit

Permalink
Improve error handling (#113)
Browse files Browse the repository at this point in the history
* Improbe error handling

* update version

* Improve error handling

* Update gemfile version
  • Loading branch information
aguspe authored Jul 29, 2024
1 parent 2dea572 commit 61195df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/generators/templates/common/gemfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ gem 'rubocop'
<%- if rspec? -%>
gem 'rubocop-rspec'
<%- end -%>
gem 'ruby_raider', '~> 1.0.1'
gem 'ruby_raider', '~> 1.0.4'
<%= ERB.new(File.read(File.expand_path('./partials/automation_gems.tt', __dir__))).result(binding).strip! %>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ gem 'selenium-webdriver'
gem 'watir'
<% when selenium_based? %>
gem 'selenium-webdriver'
<% else %>
<% when mobile? %>
gem 'appium_lib'
gem 'appium_console'
<% end %>
14 changes: 14 additions & 0 deletions lib/plugin/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module RubyRaider
module Plugin
class << self
def add_plugin(plugin_name)
return gemfile_guard unless File.exist?('Gemfile')
return pp 'The plugin was not found' unless available?(plugin_name)
return pp 'The plugin is already installed' if installed?(plugin_name)

Expand All @@ -18,6 +19,7 @@ def add_plugin(plugin_name)
end

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

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

def installed_plugins
return gemfile_guard unless File.exist?('Gemfile')

parsed_gemfile = File.readlines('Gemfile').map { |line| line.sub('gem ', '').strip.delete("'") }
parsed_gemfile.select { |line| plugins.include?(line) }
end
Expand All @@ -51,6 +55,8 @@ def plugins
private

def add_plugin_to_gemfile(plugin_name)
return gemfile_guard unless File.exist?('Gemfile')

File.open('Gemfile', 'a') do |file|
file.puts "\n# Ruby Raider Plugins\n" unless comment_present?
file.puts "gem '#{plugin_name}'" unless plugin_present?(plugin_name)
Expand All @@ -67,6 +73,8 @@ def last_plugin?
end

def read_gemfile
return gemfile_guard unless File.exist?('Gemfile')

File.readlines('Gemfile')
end

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

# :reek:NestedIterators { enabled: false }
def update_gemfile(output_lines)
return gemfile_guard unless File.exist?('Gemfile')

File.open('Gemfile', 'w') do |file|
output_lines.each { |line| file.puts line }
end
end

def gemfile_guard
pp 'There is no Gemfile, please create one to install plugins'
end
end
end
end
2 changes: 1 addition & 1 deletion lib/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.4

0 comments on commit 61195df

Please sign in to comment.