search for: toplevel_bind

Displaying 5 results from an estimated 5 matches for "toplevel_bind".

2006 Jun 26
5
How can I dynamiclly generate models?
I am trying to write a plugin, ''acts_as_commentable'', for my models - Image, Book, Music and so on, I do not want to use polymorphic association, so very model should have its own comment class. Here is my code acts_as_commentable.rb module Commentable def self.included(base) base.extend(ClassMethods) end module ClassMethods def
2006 Jul 28
0
reserved words
...def define_klass(table_name) tname = class_name_from_table(table_name) class_def = <<-end_eval class #{tname} < ActiveRecord::Base set_table_name(''#{table_name}'') end end_eval eval(class_def, TOPLEVEL_BINDING) const_get(tname) end end end end I need to somehow validate against reserved words. Any suggestions? Anything wrong with the Dynamic module? Sorry for the long post, andy -- Andrew Stone -------------- next part -------------- An HTML attachment was scrubbed... URL...
2005 Aug 16
1
Defining model classes for enumerations
I have several tables for enumerations. They all have the same content: id, name, position. I''d like to avoid the tedious work of defining a class for each one explicitly. Not least, in order to avoid clutter in the model directory. Here''s what I''ve come up with: class EnumRecord < ActiveRecord::Base def self.define_enums(*enums) enums.each do |spec|
2010 Jun 04
8
unicorn_rails cleanup (possible fix for Rails3) pushed
...'unicorn/app/old_rails'' - Unicorn::App::OldRails.new - else - ActionController::Dispatcher.new - end - when /\.ru$/ - raw = File.read(ru) - raw.sub!(/^__END__\n.*/, '''') - eval("Rack::Builder.new {(#{raw}\n)}.to_app", TOPLEVEL_BINDING, ru) + defined?(::Rails::VERSION::STRING) or + abort "Rails::VERSION::STRING not defined by config/{boot,environment}" + # it seems Rails >=2.2 support Rack, but only >=2.3 requires it + old_rails = case ::Rails::VERSION::MAJOR + when 0, 1 then true + when 2 t...
2005 Aug 19
13
Enumerations (again): Comments please
...pec[:class_name]} < BoilerPlate::Enumerations::EnumRecord def self.all return @@all if @@all @@all = find(:all, :order => ''#{order}'', :conditions => #{spec[:conditions].inspect}) end end END eval(class_def, TOPLEVEL_BINDING) enum_class = const_get(spec[:class_name]) enum_class.table_name = spec[:table_name] if spec[:table_name] enum_class end end end class Module # :nodoc: alias_method :const_missing_without_enums, :const_missing def const_missing(const_id) const_missing_without_enu...