Book Image

Instant RubyMine Assimilation

By : David L. Jones
Book Image

Instant RubyMine Assimilation

By: David L. Jones

Overview of this book

Ruby and Ruby on Rails applications can become very complex very quickly, with hundreds of different files to contend with during a typical day of development. With RubyMine, you can become much more productive and let the IDE take care of the menial tasks while you concentrate on the details and structure of your applications. Instant RubyMine Assimilation shows you how to integrate the RubyMine development environment into your everyday development process. With step-by-step instructions and practical examples, you will learn how to customize the environment precisely to suit your needs, debug and test your code, and get the most out of many other features of RubyMine. Starting with the installation of RubyMine on your preferred platform, this guide will walk you through creating your first program. You will be taken through everything from the development and testing process all the way to deploying your website for the world to enjoy. You will learn how to manage your project in RubyMine including integrating version control, testing, and debugging your projects. Furthermore, you will learn how to navigate complex projects, view database tables, and utilize the built-in console and deployment tools of RubyMine, all of which will help you become an expert developer This book will also teach you how to install and use Gems, change Ruby environments, and use code coverage and reports to enhance your testing. By the end of this book, you will be able to confidently deploy your Rails application to a server, all within the inviting environment that is RubyMine.
Table of Contents (7 chapters)

Managing your implants (Should know)


Now, we will learn how to utilize RubyMine to manage your Gems and external libraries used for your Ruby on Rails programs.

Getting ready

Start RubyMine and open the HelloWorld project that we created earlier. We will be adding an implant to enhance your assimilation process into the collective.

How to do it...

We will now use a Gem in RubyMine by showing the following simple example using the Prawn Gem:

  1. Right-click on the HelloWorld project folder in the left project panel and add a new file to your project. Name it pdf.rb.

  2. Add the following code to this new file:

    require 'prawn'
    Prawn::Document.generate("hello.pdf") do |pdf|
      pdf.font "Courier"
      pdf.stroke_color = "ff0000"
      pdf.line_width = 5
      pdf.stroke do
        pdf.circle([300, 300], 100);
        pdf.circle([350, 320], 20);
        pdf.circle([260, 325], 20);
        pdf.curve [270, 250], [340, 250], :bounds => [[270, 270],[275, 220]]
      end
      pdf.move_down(300)
      pdf.font_size = 36
      pdf.fill_color "000000"
      pdf.draw_text("You will be assimilated!", :at => [40, 40])
    
      pdf.line_width = 1
      pdf.stroke_color = "0000ff"
      pdf.move_to([0, 0])
      grid = 11
      num_lines = 51
      size = (num_lines - 1) * grid
      pdf.stroke do
        51.times do |idx|
          pdf.line([0, idx*grid], [size, idx*grid])
          pdf.line([idx*grid, 0], [idx*grid, size])
        end
      end
    end
  3. Now, right-click on the open source file and select Run pdf. You should get an error similar to in 'require': cannot load such file -- prawn (LoadError). This means that you do not have the required technology to continue the assimilation process. We need to add some Ruby Gems to allow our program to continue.

  4. Open the Settings panel and select the Ruby SDK and Gems panel from the left-hand list. This is where we also changed the version of Ruby that we are using. This panel will allow us to install some specific Ruby Gems that we need.

  5. Hit the button Install Gems... and you will see a screen like the following:

  6. Start typing the name of the Gem you wish to install, which in this case is prawn and the search will begin immediately. Scroll to the right Gem.

  7. Select the Gem in the list at the left-hand side and then hit the button Install. RubyMine will then run the Gem system and install the Gem and all of its appropriate dependencies into your system.

  8. When it is complete, select the prawn gem in the list on the right and you will see the description panel filled with various aspects of the gem for your browsing pleasure.

  9. Once completed, go back and re-run the pdf.rb program.

  10. Since this program actually generates a PDF file, we need to find where it saved the file. In the project window on the left, hit the icon that looks like the following:

    This will synchronize the files inside the folder with the project list. You should now be able to see the file hello.pdf in the project window.

  11. Double-click on this and you will see this file in whichever application you have on your computer that displays PDF files. You should see something like the following:

How it works

The code that we typed in is a simple use of the Prawn Gem. It first requires the Gem code and then starts a block of code that will begin generating the hello.pdf file on the disk. Each command then sets properties of the text, size, colors, circles, and finally draws a grid of lines on the page.