Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling #113

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading