Sha256: ab3c2e9b98568785eaeb03e8b589851a34ce62497025d7724c0020bfe074a344
Contents?: true
Size: 1.56 KB
Versions: 2
Compression:
Stored size: 1.56 KB
Contents
# code: # * George Moschovitis <gm@navel.gr> # # (c) 2004 Navel, all rights reserved. # $Id: scaffold.rb 175 2004-11-26 16:11:27Z gmosx $ require 'glue/inflector' module N module Scaffolding # Ruby is sometimes VERY surprising, the following trick is needed # to include singleton methods in other classes. # def self.append_features(base) super base.extend(SingletonMethods) end module SingletonMethods # Enchant the caller with a number of default methods. # Override the automatically generated methods as needed. # def scaffold(klass, options = {}) oid = options[:oid] || 'oid' name = options[:name] || G::Inflector.name(klass.name) list_name = options[:list_name] || G::Inflector.plural_name(name) suffix = "_#{name}" # Add methods to the scaffolded class. klass.module_eval <<-"end_eval", __FILE__, __LINE__ def view_uri "view#{suffix}?oid=\#\{@oid\}" end end_eval # Add methods to the service. if options[:index] module_eval <<-"end_eval", __FILE__, __LINE__ def index list#{suffix} end end_eval end module_eval <<-"end_eval", __FILE__, __LINE__ # TODO: add pager support here! def list#{suffix} @#{list_name} = #{klass}.all('ORDER BY oid') end def view#{suffix} @#{name} = #{klass}[@params['#{oid}']] end def save#{suffix} end def del#{suffix} #{klass}.delete(@params['#{oid}']) end alias_method :delete#{suffix}, :del#{suffix} end_eval end end end end # module
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.6.0 | lib/nitro/scaffold.rb |
nitro-0.7.0 | lib/nitro/scaffold.rb |