Edit: To be clear, I'm trying to use this kind of generator (i.e. with a 'yield' statement) not a Rails generator.
I have the following (simplified) initializer mixin in a Rails project that I could use some help with. What I wanted to do was create a generator to track Twitter API calls (this is just for debugging, I know about rate_limit_status).
require 'generator'
# Be sure to restart your server when you modify this file.
module TwitterMixin
def get_auth
@auth ||= Twitter::HTTPAuth.new(ENV['TWITTER_USER'], ENV['TWITTER_PASS'])
end
def count
@counter ||= generator.new
@counter.yield
end
def client
p "#{count} Twitter API calls this iteration"
@client ||= Twitter::Base.new(get_auth)
end
end
The problem is that I'm getting the following error:
dlopen(/Users/john/.gem/ruby/1.8/gems/json-1.2.0/ext/json/ext/generator.bundle, 9): no suitable image found. Did find:
/Users/john/.gem/ruby/1.8/gems/json-1.2.0/ext/json/ext/generator.bundle: mach-o, but wrong architecture - /Users/john/.gem/ruby/1.8/gems/json-1.2.0/ext/json/ext/generator.bundle
Which seems like a collision with the json generator, which is probably in a more enclosing scope. The main question is how to I ensure a Ruby standard library class (specifically the generator class) is called?
I'm still new to Ruby, BTW, and searching for "generators in Rails" is pretty dominated by Rails::Generator, so this may be fairly obvious. Also, I'm open to more elegant solutions to this problem that I may have missed. Thanks.