I can also immediatly see an advantage here for translations

property :name, String, :nullable => false, :messages => {:presence =>
proc {|r| translate("Please supply a name") }

There may be other way of doing this translation already but it came
to mind as a solution to a translation problem

On Jan 14, 11:35 am, heda <[email protected]> wrote:
> Yeah, the proc is what i'm going after
>
>      validates_present :network_connection, :when
> => :committing, :message => proc { |record| "what you think I am, a
> Git?!" }
>
> the context messages don't really cover it for me as the
> messagechanges not on context but the state of other properties on the
> model.
>
> Just to refer back to the example I gave before of a model which
> represents time spans (Daily, Weekly, Monthly, Quaterly, Yearly, etc)
> and then a model which references a time span and has a property
> frequency, the error message would need to change to suck in the name
> of the time span => "Please supply a #{time_span.name} frequency for
> this job"....
>
> class TimeSpan
>   property :name, String
> end
>
> class Job
>   property :frequency, Integer, :message => proc {|r| "Please supply a
> #{time_span.name} frequency for this job"}
>   property :time_span_id, Integer
>
>   belongs_to :time_span
> end
>
> On Jan 14, 11:26 am, Michael Klishin <[email protected]>
> wrote:
>
> > On 14.01.2009, at 14:08, heda wrote:
>
> > > On another note. Have you any concept objections to dynamic eval
> > > messages?
>
> > "Dynamic eval" gave me some creeps initially (I appreciate having
> > as little magic as possible in the code), but if what you mean is
>
> > > I was going to have a look and see at valid? time if the :message is a
> > > Proc and just execute it within the models scope?
>
> > just a way to do
>
> >    class SubversionOperation < ScmOperation
> >      #
> >      # Validations
> >      #
>
> >      validates_present :network_connection, :when  
> > => :committing, :message => proc { |record| "what you think I am, a  
> > Git?!" }
> >    end
>
> > then keep in mind message already handles this case:
>
> > validates_present :prop, :when => [:update, :create], :message => {
> >    :create => "message for create context",
> >    :update => "message for update context"
>
> > }
>
> > That is, you need to keep multiple contexts in mind, and thus think  
> > about keeping code simple. I call this feature
> > "callables expansion" usually. But I am all for it.
>
> > I am in the process of rewriting dm-validations spec suite from  
> > scratch, so I'd take on it as soon as I finish with most of it. I am  
> > done with 3 validators
> > already, and have pretty good set of fixtures to get up to speed with  
> > those left.
>
> > MK
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to