rfm icon indicating copy to clipboard operation
rfm copied to clipboard

Added field converter feature

Open smartacus opened this issue 13 years ago • 3 comments

Added a converters configuration option allowing custom conversion of values in resultsets. A hash of field/lambda pairs is assigned to the converters configuration key to enable the feature.

As an example, you could specify that the 'logincount' field in this User model should be returned as an integer:

class User < Rfm::Base
  config :layout => 'my_user_layout'
  config :converters => {
    'logincount' => lambda { |f| f.to_i }
  }
end

smartacus avatar Jul 23 '12 18:07 smartacus

I've been working on a huge Rails project involving Rfm, and I've run into some obscure and not-so-obscure data conversion issues, in both directions (read and write). I've patched the issues in my project but haven't addressed this in Rfm yet. When I get a chance, I'll review my code and this request and see if I can put everything together.

ginjo avatar Oct 07 '12 10:10 ginjo

@ginjo: any news on this? Looks like a nice feature...

emptyflask avatar Jul 31 '14 17:07 emptyflask

I've been saving this one until the I get the new parsing engine settled down. I'll have to work this request into the new record & field building process. Not a big deal, but I want to make sure it all fits together nicely.

ginjo avatar Aug 03 '14 09:08 ginjo