search for: define_method

Displaying 20 results from an estimated 64 matches for "define_method".

2012 Sep 11
1
define_method vs module_eval
Rails code: Accessors.send :define_method, :"default_#{name}", &block Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1    def #{name}    -ISKimRw02aC5oVgD8gxYQQ@public.gmane.org(:#{name}, [])    end    def #{name}=(value)    value = value.present? ? Array(value) : default_#{name}    _set_detail(:#{name},...
2007 May 10
13
Is there a way to do incremental search?
Say the user first enters "ruby" for search and gets 1000 results. Then he can search "rails" just in the 1000 results just returned. The common scenario is some kind of advanced search. User can incrementally add criteria and the program will narrow the results step by step. I know that at least I can use all the criteria as a whole to do the searching, but this is a waste
2005 Dec 15
3
define_method with parameters
Hi, I''m trying to write a macro which defines methods. One of these should have a parameter, but I can''t get that to work. Something like: define_method("printstuff") do puts "blabla" end works fine. But, how do I use define_method to create something like: def printstuff(the_stuff) puts the_stuff end Thanks in advance. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCw...
2006 Jun 08
3
Macros and stuff
.../new for each are practically identical. So first I DRY''d the four methods in each controller to just one and then I decided to write a single macro for all my controllers. This is the macro: def self.edit_action_for(model, options = {}) model_class = Object.const_get(model) define_method(:edit) do edit_code = lambda do @thing = model_class.find_by_id(params[:id]) || model_class.new if request.post? @thing.attributes = params[:impactable_area] if @thing.save flash[:notice] = "#{model.humanize} successfully saved."...
2014 Feb 12
61
P2V: Headless support
This introduces support to run P2V without X server. Runtime parameters are specified via kernel command line making it hopefully suitable for automated migration with a little help of PXE boot. Patchset is not squashed and represents dev. history.
2006 Mar 26
2
Shared Columns in an STI
I have a an STI table which acts_as_tree, that has a large number of classes/types. My common fields are: id parent_id name description with 4 more text fields, I could cover most of my classes if I could redefine the name of the field like this. text1 AS address1 text2 AS address2 text3 AS zipcode For one class and text 1 AS model_number text2 AS vendor Is there a construct that will allow
2007 Aug 10
3
Different ferret fields for instances of the same model?
...< ActiveRecord::Base belongs_to :property, :polymorphic => true @@ferret_fields = {...} @@ferret_fields.merge!(Property1.ferret_fields) @@ferret_fields.merge!(Property2.ferret_fields) acts_as_ferret({:fields => @@ferret_fields}) Property1.ferret_fields.keys.each do |field| define_method("#{field}") do result = property.send("#{field}") end end Property2.ferret_fields.keys.each do |field| define_method("#{field}") do result = property.send("#{field}") end end end But there are two problems in the above code: 1....
2007 Sep 30
2
Outputing to the browser, how?
Hello, I''m writting some helper methods to write forms, so I have this working code: class TableFormBuilder < ActionView::Helpers::FormBuilder ["file_field", "password_field", "text_field"].each do |name| define_method(name) do |label, *args| @template.content_tag(:tr, @template.content_tag(:td, @template.content_tag(:label, label.to_s.humanize)) + @template.content_tag(:td, super)) end end end From the documentation of content_tag, I see it has two styles: content_tag(tag,...
2011 Jan 08
4
Help How to create DSL for conditional validations
...uot;Can not have more than 3 addresses". end end end This way I want in new and edit form I can ask user to click :bypass_validation attribute and I will bypass this validation. I tried to create def valid_with_cond(name, &block) attr_accessor name define_method "svalidator_#{name}" do |*arg| if send name yield *arg end end end But after trying it in Class Person < ActibeRecord::Base valid_with_cond :test do if self.addresses > 3 errors[:base] << "Can not have more than 3 addresses"....
2007 Nov 20
2
Plugin: create instance methods dynamically in ClassMethods?
Hi all I have the following plugin code: module IncenseCrud def self.included(base_class) base_class.extend(ClassMethods) end module ClassMethods def performs_incense_crud def index list return render(:action => ''list'') end end end end In init.rb I have the following: require File.dirname(__FILE__) +
2007 Jun 01
0
[1044] trunk/wxruby2: Special memory management for Wx::Grid
...the Grid is + # not garbage collected, the associated renderers will be marked in + # the GC mark phase and so preserved. + # + # For most classes we handle GC on the SWIG side but honestly it''d be + # a whole lot more messy coding... + wx_init = self.instance_method(:initialize) + define_method(:initialize) do | *args | + wx_init.bind(self).call(*args) + + @__renderers = {} + @__editors = {} + end + + wx_set_cell_renderer = self.instance_method(:set_cell_renderer) + define_method(:set_cell_renderer) do | row, col, rendr | + wx_set_cell_renderer.bind(self).call(row, col, r...
2007 Oct 23
3
CheckListBox : delete method bug !
...h some copy/paste of wxRuby 1.9.2 for convenience). I''m running on Windows 2000. require "wx" ###################################### # Copy/Paste of wxRuby 1.9.2 additions class Wx::App def self.run(&block) app_klass = Class.new(self) app_klass.class_eval do define_method(:on_init, &block) end the_app = app_klass.new the_app.main_loop end end class Wx::CommandEvent alias :get_index :get_int end # End of Copy/Paste of wxRuby 1.9.2 additions ############################################# class Wx::CheckListBox # if the following method is define...
2006 Apr 20
11
dynamic mock object anyone?
Hi guys, got this problem with creating such a thing... hope anyone could help.. the problem: ok, now i have this mock object that would simulate a external rpc call. eg require ''models/xmlrpc_agent'' class XmlrpcAgent def create(params) 200 end end but the value of the value returned is fixed. which is quite hard for me to test the controller when different
2007 Jan 29
2
What does Reloadable mean in rails source code?
...Rails dispatcher when Dependencies.mechanism = :load. module Reloadable class << self def included(base) #nodoc: raise TypeError, "Only Classes can be Reloadable!" unless base.is_a? Class unless base.respond_to?(:reloadable?) class << base define_method(:reloadable?) { true } end end end def reloadable_classes included_in_classes.select { |klass| klass.reloadable? } end end # Captures the common pattern where a base class should not be reloaded, # but its subclasses should be. module Subclasses def sel...
2007 May 20
9
How to test for exceptions
...9;t know what I missed. Thanks in advance, Blake describe VenuesController, "on update" do before(:each) do @venue = mock("venue") @venue.stub!(:new_record?).and_return(false) @venue.stub!(:to_param).and_return(''1'') controller.class.send(:define_method, :rescue_action) { |e| raise e } end it "should raise an error if record is invalid" do stub_authorized_login Venue.should_receive(:find).and_return(@venue) @venue.should_receive(:update_attributes!).with("name" => "random text").and_return(false)...
2008 May 07
1
Assigning to the foreign key on a belongs_to association
...d/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1094,6 +1094,13 @@ module ActiveRecord instance_variable_set(ivar, new_value.nil? ? nil : association) end + if association_proxy_class == BelongsToAssociation + define_method("#{reflection.primary_key_name}=") do | target_id| + instance_variable_set(ivar, nil) + self["#{reflection.primary_key_name}"] = target_id + end + end + define_method("set_#{reflection.name}_target") do | target|...
2006 Mar 03
7
Meta Programming Help
...;, prod_id, "%pdf", "%msword"]) end end Is it possible to create one meta-method that contains the stub for these methods? I''m NOT looking for something like: def ProductFile::find_by_type(type, mode, prod_id) //code snip end Perhaps something using the define_method feature?
2007 Apr 16
5
AAF: merge search results
Hi, I have a user model that has a couple of other models(like street address, tasks). suppose User has a name field Address has a state field. so I want to provide a detailed search form each field in the user and its related models can be specified. Suppose I have a user that has a name "california", and that user has a address with the state field being "california" as
2007 May 23
8
Rails Rendering diagnostics.rhtml in Controller Spec
Forgive me if this isn''t the proper list. It''s specific to the rSpec Rails plugin. The problem is, some controller actions are rendering the "diagnostics.rhtml" template when I''m expecting it to render something else in a controller spec. I''m assuming this is the template that displays the error message and a stack trace when an error is raised in the
2006 Jun 17
5
STI versus Composition...or the headaches of one big table
Guys, I have a relationship between model classes that I believe is best represented by inheritance, but the likelihood that things will change often is driving us to composition instead. So, I have a class called Autos, and subclasses called Suvs, Minis, Mids, Sports, for example. We have been requested to avoid the STI approach to this, because of fear of a quickly growing table with