ruby

Running a Ruby Program as a Windows Service?

Is it possible to run a ruby application as a Windows Service? I see that there is a related question which discusses running a Java Application as a Windows Service, how can you do this with a Ruby application? ...

Need help improving a Ruby DSL for controlling an Arduino controlled drink dispenser (bar monkey)

I'm writing a DSL in Ruby to control an Arduino project I'm working on; Bardino. It's a bar monkey that will be software controlled to serve drinks. The Arduino takes commands via the serial port to tell the Arduino what pumps to turn on and for how long. It currently reads a recipe (see below) and prints it back out. The code for se...

Installing RMagick on Mac OS X with MacPorts

With the MacPorts version of ImageMagick 6.4.4 installed, I'm getting an error installing the RMagick gem. /opt/local/bin/ruby extconf.rb update rmagick checking for Ruby version >= 1.8.2... yes checking for /usr/bin/gcc-4.0... yes checking for Magick-config... no Can't install RMagick 2.7.0. Can't find Magick-config in /System/Libr...

To Nest or Not to Nest?

Premise: Usually during preparation of a new Ruby on Rails App, I draw out models and relations regarding user navigations. Usually I hit a place where I need to ask myself, whether or not I should go beyond the usual "rule of thumb" of nesting no more 1 level deep. Sometimes I feel the need to nest, rather than creating another namespac...

How can I use C# style enumerations in Ruby?

I just want to know the best way to emulate a C# style enumeration in Ruby. ...

Limitations in running Ruby/Rails on windows

In the installation documentation to RoR it mentions that there are many limitations to running Ruby on Rails on Windows, and in some cases, whole libraries do not work. How bad are these limitations, should I always default to Linux to code / run RoR, and is Iron Ruby expected to fix these limitations or are they core to the OS itself?...

In Ruby on Rails, how do I format a date with the "th" suffix, as in, "Sun Oct 5th"?

I want to display dates in the format: short day of week, short month, day of month without leading zero but including "th", "st", "nd", or "rd" suffix. For example, the day this question was asked would display "Thu Oct 2nd". I'm using Ruby 1.8.7, and Time.strftime just doesn't seem to do this. I'd prefer a standard library if one ex...

installing starling on windows

I am trying to install the starling gem on my windows machine. But, whenever I try to install it i get this error: Building native extensions. This could take a while... ERROR: Error installing starling: ERROR: Failed to build gem native extension. c:/ruby/bin/ruby.exe extconf.rb install starling -- --srcdir= c:\ruby-1.8.7...

Rails named_scopes with joins

I'm trying to create a named_scope that uses a join, but although the generated SQL looks right, the result are garbage. For example: class Clip < ActiveRecord::Base named_scope :visible, { :joins => "INNER JOIN series ON series.id = clips.owner_id INNER JOIN shows on shows.id = series.show_id", :conditions=>"shows.visi...

How do I use Ruby for shell scripting?

I have some simple shell scripting tasks that I want to do for example: Selecting a file in the working directory from a list of the files matching some regular expression I know that I can do this sort of thing using standard bash and grep but I would be nice to be able to hack quick scripts that will work in windows and linux wi...

What deployment directories do you use for Rails applications (deploying to a debian box)?

I wonder what's the best deployment directory for Rails apps? Some developers use directories such as /u/apps/#{appname}. Are there any advantages when using /u/apps/#{appname} instead of /var/www/#{appname} or other OS default directories? Obviously I want to pick the directory with the best security properties and the least friction f...

Multiple database connection

Hi, I'm trying to understand the best way to get the connection to my databases. At the moment I've got a method wich parses the url (depending on the url called the application has to connect to a different database, like customer1.xxx.com will connect to the customer1 database) and calls ActiveRecord::Base.establish_connection(conn...

RSpec Stories and Specs: When to use what?

So I want to start using RSpec stories, but I am not sure where writing controller, model and view specs fit in. For example, you have the story "Logging in" with "User provides wrong password" scenario, don't you end up testing the same stuff than controller/model specs (response.should render..., user.should be_nil, etc.) So my ques...

non-DB attr_accessor attribute persistence in Rails

I have an application in which attr_accessor is being used to keep temporary data for a model which will be passed to a rake task. Seeing there is not a database field for these attributes and they are not being calculated from database data, will the attr_accessor data persist and be available to the rake task? What happens if I need ...

Need assistance with serial port communications in Ruby

I need to do some communications over a serial port in Ruby. From my research, it appears that there aren't many modern libraries for serial communications and the newest material I can find is from 2006. Are there any gems that I'm not aware of? I ultimately need to maintain communications with a serial device attached to USB (I can ...

How do I make Ruby Gems installations on Windows use MinGW for making and compiling?

Trying to update some gems on a Windows machine and I continually get this error output for gems that do not have pre-compiled binaries: Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt...

How to get 'Next Page' link with Scrubyt

I'm trying to use Scrubyt to get the details from this page http://www.nuffieldtheatre.co.uk/cn/events/event_listings.php?section=events. I've managed to get the titles and detail URLs from the list, but I can't use next_page to get the scraper to go to the next page. I assume that's cause I'm not using the correct pattern for the next p...

$SAFE on ruby

I want to be able to run unstrusted ruby code. I want to be able to pass variables to said untrusted code that it may use. I also want said code to return a result to me. Here is a conceptual example of what I am thinking input = "sweet" output = nil Thread.start { $SAFE = 4 #... untrusted code goes here, it uses the input variabl...

Continuous Integration setup for ruby projects on linux server

I would like to use open source tools if possible. here are 2 links I found but haven't tried them - http://pivots.pivotallabs.com/users/chad/blog/articles/471-continuous-integration-in-a-box-exploring-tsttcpw http://laurentbois.com/category/continuous-integration/ ...

Rspec - problems with switching from plugins to gems

When dropping the use of rspec and rspec-rails plugins and switching to the gem versions instead, is there anything extra I have to change in spec_helper.rb or something to make the specs in my app see the change? I can no longer get my specs to run successfully anymore after deleting the plugins and installing the gems (1.1.8). More...