ruby

What comes first in Ruby's object model?

I've been reading Metaprogramming Ruby and the object model is like the chicken or egg dilemma. In Ruby 1.8, the Object class is an instance of Class. Module's superclass is Object and is an instance of Class. Class' superclass is Module, and it is an instance of Class (self-referential). Say class SomeClass; end is defined somewhere; ...

How can I loop through each of the days of a given week in Ruby?

I am defining monday and friday using the following: @monday = Date.today.at_beginning_of_week @friday = 5.days.since(@monday) But I actually need, for any given day, to loop through Monday, Tuesday, Wednesday and take that date and put the output into a column. <th>Monday</th> <th>Tuesday</th> etcetera A given row, for example, ...

Parsing Very Large XML file with Ruby on Rails (1.4GB) -- Is there a better way than SAXParser?

Currently, I'm using LIBXML::SAXParser::Callbacks to parse a large XML file containing data 140,000 products. I'm using a task to import the data for these products into my rails app. My last import took just under 10 hours to complete: rake asi:import_products --trace 26815.23s user 1393.03s system 80% cpu 9:47:34.09 total The pro...

Rails Authentication

Hey, i need some help with rails, again! Last it was about Authlogic.. Well I'm gone a bit backward since.. I mean, Authlogic isn't a Authentcate system i like.. So now i wan't you guys to tell me what you think is the best! I going to use it to a project of mine. Where there has to be a few roles like Admin, User and Guest.. So might y...

Changing Passwords Over Multiple Servers and Services

Hi all, I am looking to automate the changing of passwords across multiple services and servers. For example: I want to change the root paassword to all of my web servers at once. I am thinking of writing a ruby script, but have you guys run across anything already written? If so, would that also give me the ability to change other sys...

how to specify a BIGINT in a rails scaffold?

I am trying to create a model in ruby that uses a BIGINT datatype (as opposed to the INT done by :integer). I have search all over Google, but all I seem to find is "run an SQL statement to alter the table to a BIGINT" - This seems a bit hack-ish to me, so I wanted to know if there was a way to specify a bigint in the ruby system like ...

Any Ruby AMF clients out there?

Hi, I'm looking for a way to push/receive AMF0 / AMF3 messages in Ruby(Rails). From what I read rubyAMF can only act as a server. What I need is a library that allows client access to FMS/Wowza.Any ideas? ...

How do I test a ruby Mixin Module?

I'd like to know the best way to approach testing ruby mixin modules, in this case for use with ActiveRecord models, but really this is a general quesiton that applies to any class that you are extending with a mixin. Is it better to attempt to stub all of the necessary functionality of the Class that your mixin is extending, or just te...

When using truncate I get the following error "index 113257 out of string"

What does this error mean? Here is the line of code that generates it apts[ndex] = truncate(results[ndex][:public_note].to_s,:length => 300) results is an array of activerecord objects ...

Ruby on Rails: Uploading a modifed site.

I'm having a heck of a time getting a site I modified to work correctly. I didn't set the site up originally, and since the person that set it up no longer works with me I had to learn ruby just to make some changes. I made all the changes in the development server and everything worked fine. Then I did a diff on the production and d...

Stubbing tests when using Ruby Mechanize

Hi Everyone, I've been trying to use Mocha to do some stubbing for tests on code using Mechanize. Here is an example method: def lookup_course subject_area = nil, course = nil, quarter = nil, year = nil raise ArgumentError, "Subject Area can not be nil" if (subject_area.nil? || subject_area.empty?) page = get_page FIND_BASIC_...

parsed xml file: skip creation if blank?

This could be a HappyMapper specific question, but I don't think so. In my app, users can upload their blog subscriptions (via an OPML file), which I parse and add to their profile. The only problem is during the parsing, or more specifically the creation of each subscription, I can't figure out how to skip over entries that are just ...

RegEx Help in Ruby

My sample file is like below: H343423 Something1 Something2 C343423 0 A23423432 asdfasdf sdfs #2342323 I have the following regex: if (line =~ /^[HC]\d+\s/) != nil puts line end Basically I want to read everything that starts with H or C and is fol...

error when installing mysql ruby gem on OSX 10.6.3

So I am getting the same issue as mentioned here - http://stackoverflow.com/questions/1366746/gem-install-mysql-failure-in-snow-leopard But I haven't been able to get it fixed using the answers on this link. Here's a brief history - I had MAMP on my machine, but now I downloaded the latest MySQL from mysql.com and installed version 5...

Client authentication with RubyLDAP ldap

Hello all, I'm trying to implement a feature that uses LDAP over SSL (SSL, not TLS), it needs to connect to a SSL-enabled LDAP server (i.e OpenLDAP), bind and then do any additional queries. It also needs to support client-authentication, and this is where things get tricky: The client is a web application written in Ruby, and we are us...

How do I find all the datetimes that happen on a particular date in ruby?

I have a method which goes through each day of the week: def dates_week(d, delim) "<tr>" + (d.beginning_of_week...(d.beginning_of_week+5)).map do |day| "<#{delim}> #{yield(day)} </#{delim}>" end.join + "</tr>" end For each day of the week, I plug that as an arg into a method (or maybe a named_scope, haven't figure...

What is the advantage of creating an enumerable object using to_enum in Ruby?

Hi, Why would you create a proxy reference to an object in Ruby, by using the to_enum method rather than just using the object directly? I cannot think of any practical use for this, trying to understand this concept & where someone might use it, but all the examples I have seen seem very trivial. For example, why use: "hello".enum_fo...

Passenger: "Missing these required gems redgreen"

Hello, total ruby newbie, trying to setup a Rails/MongoDB application on Mac OS X Snow leopard. Installed Ruby 1.9.1 and RubyGems 1.3.7, which ruby and which gem point to the same directory. I'm using the Snow Leopard built-in apache and Passenger 2.2.11. I'm using the rails template from the mongo-site which seems to work okay overall...

Change paperclip tmp files location

Hello, Is it possible to move the (/tmp/stream*) tempfiles generated by paperclip to another location like /railsapp/public/tmp without changing tmpfiles for the whole app enviroment? I would like to show a preview of the uploaded file if valdation fails on the model. Best regards. Asbjørn Morell ...

Ruby with LDAP or AD

Hi, Is there a way of deciding and confirming with facts regarding, which is better and easier to integrate with Ruby. LDAP or ActiveDirectory? Thanks, Ivar ...