ruby

How do I get Rails to exclude some bundled gems from plugin-loading?

I have a Rails application that uses Bundler for dependency management. I've got the following in my Gemfile: # default group: gem 'json' group 'development' do gem 'my_profiler' end group 'test' do gem 'mocha' end group 'deployment' do gem 'foo' end I call Bundler.setup(:default, RAILS_ENV.to_sym) and Bundler.require(:defaul...

Ruby 1.9 bug? -- Array.permutation

While trying problem 41 from the Euler Project, I ran across what seems to be a bug in the Ruby 1.9 implementation of Array.permutation. Here's the problem code isolated: n = 4 slice = '987654321'.chars.to_a[-n..-1] puts "slice = #{slice.join}" slice.permutation(n) {|perm| puts perm.join} slice2 = slice.dup puts "slice2 = #{slice2.join...

Rake vs Thor for automation scripts?

I want to automate things like: Creating a new Rails app with pre-selected database, git initialize it, create heroku project, commit all files etc Upload all files in folder to another computer through ssh, but do not overwrite files Upgrade Ubuntu, install all basic packages through apt-get These kind of tasks. From what I have un...

Using Rake or Gem for building scripts?

I want to build scripts that automatize things for me. Here is an example of what I want to do: Create new rails app (rails new application_name --database=mysql) Jump to folder Initialize git (git init; git add .; git commit -m "first commit"; git remote add name address; git push name master) Create heroku project (heroku create; gi...

How to select array elements in a given range in Ruby?

I have an array with let's say, 500 elements. I know I can select the first 100 by doing .first(100), my question is how do I select elements from 100 to 200? ...

Should I host gems in GitHub or RubyGems?

I've read that RubyGems is de-facto hosting for gems. I host all my Rails projects on GitHub. So my questions are: Are there any reasons for hosting my gems on GitHub and not RubyGems? Does RubyGems have private repositories like GitHub? I've read that jeweler is nice for creating gem skeleton. On their webpage it sounds like it uplo...

Use Capistrano for Rake tasks?

Is Capistrano only used for deploying Rails apps? Basically I want a scripting framework to handle all server/client scripting for me. Examples: Updating Ubuntu, installing gems with dependencies etc. Creating a new Rails app, Git initialize it and commit, create Heroku project and upload the app. Automatize basic file/folder operati...

Rails + ActiveScaffold -> set_default_options

I can't seem to set default options at the ApplicationController level. I can do it just fine at the Controller level, but I want to be able to set some defaults here. This is the code that I'm using (for example): ActiveScaffold.set_defaults do |config| config.update.link.label = "" config.list.per_page = 15 end Any help wo...

Why can't I 'break' out of this Ruby block?

Hi, I have this Ruby block: status = '' build.parse do |entry| puts "parsing an item" puts entry.title if entry.title =~ /FAILURE/ then puts "failure" status = "FAILURE" else status = "SUCCESS" end puts status break entry if status == ...

Gem framework for creating gems with parameter lists?

I want to create some Gems with parameters lists when i run: my_app --help. Just like all the gems (rake, rails etc). Example: Usage: rails new APP_PATH [options] Options: -J, [--skip-prototype] # Skip Prototype files -T, [--skip-test-unit] # Skip Test::Unit files [--dev] # Setup the application ...

Ruby PDF:Toolkit using pdftotext

Hi, I'm converting pdf files in my Ruby project. I'm using the pdf toolkit gem for this. The documentation shows how you can use pdftotext pdftotext(file,outfile = nil,&block) In my project I am converting a PDF file without any arguments and can just do this: PDF::Toolkit.pdftotext("file.pdf", "file.txt) If I run it from...

Do I have use of Chef if I'm using Heroku?

I use Heroku to deploy my Rails apps. But I thought about learning Chef to automatically set up the development infrastructure, but Im not sure. So to put it very simple, are there any reasons for me to learn Chef? ...

Successfully calling a WCF Service from Ruby? Anyone?

I'm trying to integrate a rails application with a WCF service. I've tried soap4r and Savon with no love at all. As far as I can tell, none of the Ruby libraries support the newest version of SOAP. The error that I was getting was: Cannot process the message because the content type 'text/xml;charset=UTF-8' was not the expecte...

When are modules included in a Ruby class running in rails?

I'm trying to write a method that tells me every class that includes a particular Module. It looks like this - def Rating.rateable_objects rateable_objects = [] ObjectSpace.each_object(Class) do |c| next unless c.include? Rateable rateable_objects << c end rateable_objects end Where "Rateable" is my module that I'm in...

A step by step small app creation guide in Ruby

Hi. I'm looking for a step to step tutorial to make an app, not so complex in Ruby, so students can do it. By now, i have only medium-big examples that i have developed for companies some years ago,but they require extra knowledge as i used diff frameworks and libraries and i want something that can be done only with the ruby interpreter...

background task with multiple workers sharing one rails instance in memory

I need to query mulitple apis to get certain data for each user. I need to do this as a background task. Now there are a lot of users. And ideally I would like all this to happen in parallel. So I could insert a job of each user/api combination. And say have 4 delayed_job workers process all the jobs. The problem I am facing with this,...

Fooling Ruby's case operator, ===, with proxy objects

I'm trying to make a proxy object that transfers almost all method calls to a child object, essentially the delegator pattern. For the most part, I'm just using a BasicObject and passing every call with method_missing to the child object. So far, so good. The trick is that try as I might, I can't fool Ruby's case operator, so I can't ...

Custom Logging Best Practices in Ruby

What are best practices for managing custom logging in Ruby? Should I be monkeypatching logger to do what I want? Or extending from it? Or delegating? What's the rubyish way? I'm sick of custom hacks for this; I'd like something cleaner, and ideally more elegant. ...

Ruby string to octal?

How can I convert "755" to 0755 in Ruby? I want to pass permissions to a method using a string and then convert it for chmod use. ...

eruby tags nesting?

I'm currently hosted on a Mediatemple gridserver. I'm writing a site to teach myself Ruby - straight ruby, no rails. I've run into a few errors that appear to be a result of nested tags. For example: eruby requires <% %> tags around ruby code. If I try to use erb templating I'm stuffed - <% template = ERB.new <<-EOF The value of x i...