Displaying 20 results from an estimated 10000 matches similar to: "OpenHash class I thought I would share..."
2007 Dec 21
0
pretty neat Mash class (Magic Hash)
class Mash < Hash
  def method_missing(name, value=nil)
    key = name.to_s.sub(/[=?!]$/,'''').to_sym
    self[key] = value if name.to_s[-1,1] == "="
    self[key] = Mash.new unless self[key] || value
    return self[key]
  end
end
Its like OpenStruct...so what can you do?
require ''pp''
m = Mash.new
m.first_name = "john"
m.last_name =
2011 Jul 11
2
Can't get this Rspec test to pass
Hello,
  I''m completely new to Rspec testing and I''m finding it very difficult to
mock specific objects.
In this test, I have a before block setup as such:
[code]
  before do
    setup_controller_for_warden
    controller.session[:operation_id] = 1
    @operator = Factory :operator
    sign_in :operator, @operator
            
    @persist_herd = Herd.new
   
2007 Sep 25
16
putting away HashWithIndifferentAccess
Hey, campineros.  And many good handshakes to zimbatm for getting
some patches applied.
So, yeah, I''d really like to get rid of any serious dependancies with
this 1.6 release.  Anything that''s not in stdlib has to go.  Of course,
camping-omnibus will still assume the whole ActiveRecord, Markaby,
Mongrel setup that''s in the history books.
Metaid can be removed and
2005 Dec 18
0
Extending AR::B to provide translations
Hi all,
I want to extend AR::B is such a way as to be able to support and  
display different language versions of objects. I know of and have  
tried Globalize but still want to do this on my own for a multitude  
of reasons (the educational value probably being most important).
My table for the objects has columns named like en_name, de_name,  
fr_name, en_description, de_description,
2010 Mar 18
3
method_missing
i''m using method_missing to implement a simple metaprogramming that
checks for account rights.
in Account << ActiveRecord::Base i defined:
def method_missing(m, a = {})
  if m.to_s =~ /^has_right_(.*)$/
  ... calls another method passing $1 parameter
  end
end
it seems to override some of the active record methods based on method
missing. in the console it seems to work ok so i
2006 Mar 03
7
Meta Programming Help
I have the following two methods:
  def ProductFile::find_images(mode, prod_id)
    # convert to symbol in case it is not (most commonly it may be a String)
    mode = mode.to_sym
    case mode
    when :all, :first
      ProductFile::find(mode, :conditions => ["product_id = ? AND
file_type LIKE ?", prod_id, "image%"])
    end
  end
  def ProductFile::find_documents(mode,
2006 Aug 03
1
routeset mapper problem
hello,
I installed a rails app on dreamhost, which I''m building based on the 
Comatose plugin, and it went smoothly for the first version.
Now I uploaded a second version where I broke down the Comatose code 
into a regular rails app, which works alright locally, but can''t get 
routing to work the same as before on the server. I believe I 
double-checked all gotchas mentioned
2011 Mar 29
0
Issue / code smell in AssociationProxy
I came across an issue in my code and after a hard debug session I
found something that smells.
First the context of my issue. I have a AR object that has a
polymorphic belongs_to currently tied to nothing, I want to dump it to
YAML.
    record.to_yaml
This raises the following exception:
    TypeError: wrong argument type nil (expected Data)
    	from
2006 Oct 13
2
win32-mmap - trying to marshal self
Hi all,
I realized the current implmentation has a problem - you can only get the last value set?  I realized, after looking at the old C code, that it actually stores values in a hash and marshals the hash, not the values themselves.
That seemed clunky to me, though.  I thought it would be more interesting if we just marshalled the entire mmap object and passed that back and forth. 
2007 Sep 07
4
Ferret DRB - can add/edit index, but can''t search
I''m trying to use the Ferret DRB server to avoid concurrency issues when
using multiple mongrels.  I can successfully add and edit data on my
index via the DRB server, however, when I search the index, I get the
following error:
DRb::DRbConnError (DRb::DRbServerNotFound):
    /usr/lib/ruby/1.8/drb/drb.rb:1647:in `current_server''
    /usr/lib/ruby/1.8/drb/drb.rb:1709:in
2006 Sep 04
2
"include" versus "extend" - what's the difference
Hi,
Just wondering when one would use "include" over "extend"?  Both seem to 
bring in methods to the class no?
The context is I''m just trying to understand why both are used with the 
acts_as_audited plugin:
Full extract from plugin (used within here):
==================================================
# Copyright (c) 2006 Brandon Keepers
#
# Permission is hereby
2007 Sep 04
11
returning(...) ?
The following construct is an ActiveSupport-ism:
  returning(Foo.new) do |foo|
    ...
  end
I don''t especially like it, since it''s both more verbose and less efficient
than the direct alternative:
  foo = Foo.new
  ...
  foo
It doesn''t occur many times in Merb, so does anyone agree with me that it
should be removed?
I tried doing this (patch attached) and I find
2006 Jan 19
2
Easy way to handle form input without a model class?
I have a couple forms that I''d like to be able to validate and
automatically populate, but it shouldn''t be based on AR.  In fact I
often have a bunch of small forms that I can''t really justify writing
a whole new model class for anyway.  I''d like to validate the form
input, and then use rails helpers to automatically populate the form
if validations fail. 
2006 Apr 10
0
Inheriting data from one model to another
Hello
I''ve been struggling with something for hours that I thought would be
a simple job. Hopefully somebody can shed some light on what I''m
trying to do :o)
First of all I''ll explain what I''m trying to achieve. In a store
application I want to have products and product variations. A product
variation should inherit all of its properties from product unless
2007 Nov 12
0
Workers calling Workers
Hello,
 
We are working on a centralized report generating project, which calls
for data processing on different servers and then centralizes the
reports into a single project.  What we would like to do is have a
Monitor BackgrounDRb worker call another BackgrounDRb worker to process
data on a different server, and then have our Monitor Worker collect the
data and then store it according to our
2007 Jul 07
0
[patch] trunk markaby fix
so i guess the parser changed or something..
-------------- next part --------------
Index: camping.rb
===================================================================
--- camping.rb	(revision 194)
+++ camping.rb	(working copy)
@@ -7,7 +7,7 @@
 c=self/c;c="//"+ at env.HTTP_HOST+c if c[/^\//];URI(c)end;def/p;p[/^\//]?@root+p :
 p end;def errors_for o;ul.errors{o.errors.each_full{|x|li
2010 Apr 07
0
Need help with ActiveWarehouse-ETL-0.9.1 PG connection problem
I am trying to load conversion data into a postgresql database using
activewarehouse-etl.  I can create a flat file output from the
conversion data without problem.  However, when I try to load into the
table using the information contained in config/database.yml I see
this error:
/usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/
base.rb:1959:in `method_missing'':
2006 Jul 02
7
Generic SingleTable inheritance
Hi all,
I would like to discuss a design idea I have in mind with you, in order 
to get critical feedback.
ActiveRecord supports single table inheritance(STI) "per se", BUT you 
must add all possible instance variables(properties) of all subclasses 
to the "base table"(as columns). I would like to circumvent this 
restriction.
Say we have a
  class AbstractGenericThing <
2006 Mar 09
1
[TIP] Making an intelligent form fields
After searching arround I found a quite smart solution to me for binding 
form fields to model in an active way. I use aggregations with single 
value objects such as
class Percentage
   attr_accessor :value
   def initialize(value)
     @value = (value.is_a? String) ? value.tr('' %'', '''').to_f : value
   end
   def to_s
     return unless value
    
2009 May 03
1
Localizing attributes when using I18n
Currently I''m developing a multilingual app on rails 2.2. I liked very
much the idea of Xavier Defrang to provide a locale-aware accessor for
the fields that needs a translation: http://defrang.com/articles/2005/12/02/playing-with-rails-i18n
I modified code a little to make it work with rails 2.2:
  def self.localize(*attribute_names)
    attribute_names.each do |attribute_name|