Displaying 20 results from an estimated 49 matches for "instancemethods".
Did you mean:
instance_methods
2006 Sep 25
3
Problem stubbing instances referred to by constants
Hi James,
An instance retains its mocha between tests if that instance is
pointed to by a constant. The simplest failing test is something like
(add as a new file in mocha/test)..
#--code--
require File.join(File.dirname(__FILE__), "test_helper")
require ''stubba''
class WemStubbaTest < Test::Unit::TestCase
Arr = [1, 2, 3]
def test_a
2006 Sep 19
1
Callback sto InstanceMethods in a plugin
Hello there,
I''m currently building a plugin, for which I need a before_save
callback. The method I want to call is in module InstanceMethods, but
when I add a before_save foo, foo, as defined as an InstanceMethod,
never gets called.
This is the first plugin I''m building, after only two weeks of fiddling
with Ruby and Rails, so if anyone is kind enough to help me out.... :)
--
Posted via http://www.ruby-forum.com/.
--~--~-...
2006 Apr 10
3
Simple act_as template
Hello !
I posted a simple template to show how to add ''act_as_whatever'' to
ActiveRecord.
I think this might be useful to others as there are some trickery ruby
things in this
file.
Here is the template : http://textsnippets.com/posts/show/384
Gaspard Bucher
--
Posted via http://www.ruby-forum.com/.
2006 Jun 21
1
Plugin Panic! - no accessing a model''s class methods?
...super
base.extend(MacroMethods)
end
# declare the class level helper methods which
# will load the relevant instance methods
# defined below when invoked
module MacroMethods
def acts_as_copyable
include FakeActiveRecord::Acts::Copyable::InstanceMethods
end
end
# Adds instance methods.
module InstanceMethods
def copy( options = {} )
@copyable_attributes = self.attributes
@copyable_attributes.delete ''id''
options.each do |key, value|
next if key.class == S...
2007 Nov 27
1
Plugin - How to access object from instance method
...acts_as method from an instance method? Probably
some sort of accessor... but where?
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_test
object = Object.new ## This object needs to be accessible from the
Instance Methods
end
include Acts::As::Test::InstanceMethods
end
module InstanceMethods
def do_something
return object.process ## object created in acts_as_test
end
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Rub...
2006 Sep 04
2
"include" versus "extend" - what's the difference
...rforming the action. This
defaults to
# <tt>:current_user</tt>.
#
# == Database Schema
#
def acts_as_audited(options = {})
# don''t allow multiple calls
return if
self.included_modules.include?(CollectiveIdea::Acts::Audited::InstanceMethods)
include CollectiveIdea::Acts::Audited::InstanceMethods
class_eval do
extend CollectiveIdea::Acts::Audited::SingletonMethods
cattr_accessor :non_audited_columns,
:audited_user_class_name, :audited_user_method
self.non_audited_columns = [self.pr...
2006 Jun 26
5
How can I dynamiclly generate models?
...end"
self.class_eval class_def
has_many :comments, :class_name=>"#{self.name}::Comment",
:order=>''created_at desc'', :dependent => :delete_all
extend Commentable::SingletonMethods
include Commentable::InstanceMethods
end
end
module SingletonMethods
end
module InstanceMethods
end
end
init.rb
require ''acts_as_commentable''
ActiveRecord::Base.send(:include, Commentable)
image.rb
acts_as_commentable
This results in Image::Comment, Book::Comment...(I have no idea ab...
2007 Aug 30
1
alias_method_chain stack level too deep in Rake test only
...an odd error. I have the following module:
module ActionController
module SslSupport
def self.included(base)
raise "#{base} does not define url_for" unless
base.method_defined?(:url_for)
unless base.respond_to?(:url_for_without_ssl_supprt)
base.send :include, InstanceMethods
base.send :alias_method_chain, :url_for, :ssl_support
end
end
module InstanceMethods
def url_for_with_ssl_support(options)
new_options = options.dup
if options.kind_of?(Hash)
new_options.merge!({ :only_path => false }) if request.ssl?
^ ur...
2006 Jan 30
9
Something as after_successful_validation?
I need to call callback only if the validation was successful, but it
seems it is called also when validation fails.
--
Posted via http://www.ruby-forum.com/.
2011 Jul 11
2
Can't get this Rspec test to pass
...t_scope_for($1) if name.to_s =~
/^current_scope_for_(.*)/
super
end
def current_scope_for(scope)
Thread.current[scope.to_sym]
end
def acts_as_scope_manager(scope, *args)
options = args[0].extract_options! if args
send :include, InstanceMethods
set_global_scope(scope,options[:with_global_scope]) if
options[:with_global_scope]
send :before_filter, "set_scope_for_#{scope}".to_sym if
self.ancestors.include? ActionController::Base
send :default_scope, where(scope.to_sym =>
send("current_scope_for...
2012 Jan 23
0
Problem loading modules through ActiveSupport on_load
...app/models/a.rb**
class A
has_history
end
**# lib/history.rb**
module History
module Model
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def has_history(options = {})
send :include, InstanceMethods
end
end
module InstanceMethods
# methods ...
end
end
end
**# config/application.rb**
config.autoload_paths += %W(#{config.root}/lib)
**# config/environment.rb**
ActiveSupport.on_load(:active_record) do
include History::Model...
2008 Jun 12
1
Which "get" is being used in Controller spec
...is being used? I checked RDoc of RSpec and RSpec on
Rails, but didn''t find "get".
In Rails RDoc, I found the following "get"s.
get ActionController::Integration::Session
get ActiveResource::Connection
get ActiveResource::CustomMethods
get ActiveResource::CustomMethods::InstanceMethods
I''m not sure which one is working. But after playing a while, I noticed
"get" doesn''t take "path" as a parameter. For example,
get "users"
doesn''t work. I also need to know about "post" because some code I saw seems
to be passing...
2009 Mar 23
3
Spec::Rails, "model.should have(1).error_on(:attribute)" passes when?
Spec::Rails people,
I''m curious about:
- model.should have(1).error_on(:attribute)
displayed in the URL below:
http://rspec.rubyforge.org/rspec-rails/1.2.2/classes/Spec/Rails/Extensions/ActiveRecord/InstanceMethods.html
The Rspec peepcode screencast suggests that
model.should have(1).error_on(:attribute)
should pass if
model.send(:attribute)
returns nil
For me, I get an exception from the rspec script.
My work-around is simple.
Instead of:
- model.should have(1).error_on(:attribute)
I Use:
-model.send...
2006 Jun 30
0
SOAP responses blowing up memory usage
...e have a ActionWebController method that iterates
over a bunch of AR objects (say ~30,000) and converts them to struts.
The controller method automagically converts the array of Struts to
SOAP objects as advertised. There''s a point in
ActionWebService::Dispatcher::ActionController::InstanceMethods#dispatch
_web_service_request (file action_web_service/dispatcher/
action_controller_dispatcher.rb), where memory usage absolutely blows
up when passed large arrays. Monitoring top, it looks like the app
will grow to around 50mb and then when it does the
InstanceMethods#web_service_create_r...
2006 May 11
1
acts_as_paranoid and nested scopes in Rails 1.1
...----------------------------------------------
module VeryNew
#...
module ClassMethods
def acts_as_very_new
unless is_very_new? # don''t let AR call this twice
class << self
alias_method :find_with_old, :find
end
end
include InstanceMethods
end
# end
module InstanceMethods #:nodoc:
def self.included(base) # :nodoc:
base.extend ClassMethods
end
module ClassMethods
def find(*args)
with_very_new_scope { find_with_old(*args) }
end
protected
def with_very_new_scope(...
2006 May 11
0
acts_as_paranoid, aliasing and nested scopes in Rails 1.1
.../paranoid.rb):
#--------------------------------------------------------------BEGIN
module VeryNew
#...
module ClassMethods
def acts_as_very_new
unless is_very_new?
class << self
alias_method :find_with_old, :find
end
end
include InstanceMethods
end
#...
end
module InstanceMethods #:nodoc:
#...
module ClassMethods
def find(*args)
with_very_new_scope { find_with_old(*args) }
end
protected
def with_very_new_scope(&block)
with_scope({:find => {:conditions =&...
2006 Mar 28
0
How to set session variable in plug-ins
...bol as array index" error.
module Legacy
module Rails #:nodoc:
module Test #:nodoc:
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def uses_test_plug(options = {})
class_eval do
extend ::Legacy::Rails::Test::InstanceMethods
end
before_filter do |controller|
set_aaa_uid("jdoe")
end
end
end
module InstanceMethods
def set_aaa_uid(uid)
session[:aaa_uid] = uid
end
end
module SingletonMethods
end
end...
2009 Sep 11
0
Need help with extending a plugin
...aggable_extensions.rb looks like
module ActiveRecord
module Acts
module TaggableExtras
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def acts_as_taggable_extras(options = {})
include ActiveRecord::Acts::TaggableExtras::InstanceMethods
extend ActiveRecord::Acts::TaggableExtras::SingletonMethods
end
end
module SingletonMethods
#nothing here yet
end
module InstanceMethods
#...some instance methods here, added to taggables
end
end
end
end
--
Posted via http://...
2006 May 17
3
Help mixin in class methods
Starting to feel more confident and code is DRYing up nicely, but I''ve
hit a brick wall here and hoping someone can help me.
I''ve got a module, TrustRanking, which extends a number of model''s
instance methods, and I want to extend their class methods too, but I
can seem to work out how to do it.
Simply including the module from the class works a treat for the
2007 Jul 22
2
Seek brilliant Rails programmer to add one field to acts_as_taggable
...arameter to this tag.rb. It''s as though the tag.rb
instance is magically created without leaving a trail or sequence of
events that I can modify.
I was hoping I could ''go in the front door'' and simply modify the
''tag_with'' code such as this;
module InstanceMethods
def tag_with(list, project_id)
Tag.transaction do
taggings.destroy_all
Tag.parse(list).each do |name|
if acts_as_taggable_options[:from]
send(acts_as_taggable_options[:from]).tags.create(:name =>
name, :project_id => project_id).on(sel...