Re: [DataMapper] Adding custom methods to a model ?
what you're doing there is defining a class method named more_than_fifty? a method declared like that can be called from the class itself, not an instance of it. So, you end up with: Day.more_than_fifty? instead of: day = Day.new day.more_tan_fifty? to add instance methods to a class, just declare them like this: def method_name # do something end that is, without using self On Thu, Mar 7, 2013 at 9:55 AM, Pierre-Adrien Buisson wrote: > Hey guys, > > I'm beginning with Sinatra and using DataMapper as my ORM tool of choice. > I've been doing great, playing with this today, but I'm now stuck. I'd like > to add a custom method to one of my models, that would check some values of > an instance, make some comparisons and return a boolean. > > I tried the following : > > class Day > include DataMapper::Resource > > property :id, Serial > property :day_number, Integer > property :status, Integer, :default => 0 > property :date, Date > * > def self.more_than_fifty? > # Just for the sake of the example > rand(1..100) > 50 > end* > end > > But didn't work. I've seen one or two cryptic messages on Stack Overflow > about DataMapper::Model.append_inclusions, but not enough for me to > understand and get it working. > Anyone who could help me around here ? Thanks a lot for your time guys. > > Paddy > > -- > You received this message because you are subscribed to the Google Groups > "DataMapper" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to datamapper+unsubscr...@googlegroups.com. > To post to this group, send email to datamapper@googlegroups.com. > Visit this group at http://groups.google.com/group/datamapper?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To unsubscribe from this group and stop receiving emails from it, send an email to datamapper+unsubscr...@googlegroups.com. To post to this group, send email to datamapper@googlegroups.com. Visit this group at http://groups.google.com/group/datamapper?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[DataMapper] Adding custom methods to a model ?
Hey guys, I'm beginning with Sinatra and using DataMapper as my ORM tool of choice. I've been doing great, playing with this today, but I'm now stuck. I'd like to add a custom method to one of my models, that would check some values of an instance, make some comparisons and return a boolean. I tried the following : class Day include DataMapper::Resource property :id, Serial property :day_number, Integer property :status, Integer, :default => 0 property :date, Date * def self.more_than_fifty? # Just for the sake of the example rand(1..100) > 50 end* end But didn't work. I've seen one or two cryptic messages on Stack Overflow about DataMapper::Model.append_inclusions, but not enough for me to understand and get it working. Anyone who could help me around here ? Thanks a lot for your time guys. Paddy -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To unsubscribe from this group and stop receiving emails from it, send an email to datamapper+unsubscr...@googlegroups.com. To post to this group, send email to datamapper@googlegroups.com. Visit this group at http://groups.google.com/group/datamapper?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[DataMapper] Re: Datamapper and setex from redis
Yep, I am using datamapper with redis, so, I would like to set my objects with this redis function your know. Any way to make this happens? On Wednesday, February 27, 2013 2:27:28 PM UTC-3, Abe Voelker wrote: > > Are you using DataMapper to store your models in a redis keystore (e.g. > using dm-redis-adapter), or are you using a relational database and just > wondering how you can get a similar feature? If it's the latter, I don't > know of any relational databases that has such a feature built-in, so > DataMapper can't really do it by itself; I would probably create > delayed_jobs to handle the destroys: > > https://github.com/collectiveidea/delayed_job > > On Wednesday, February 27, 2013 11:02:58 AM UTC-6, Thiago Cifani wrote: >> >> Hello guys, >> >> I was wondering if I could use this kind of set expiration with >> datamapper but I am kind of lost. I've tried to search about this subject >> but sadly I didn't find any help it all in google. Could you, please, give >> me any lead to help with this thing? I need to set some delete time >> expiration to my objects, to destroy themselves when some minutes or hours >> after their usage. Please, any lead will be appreciated. >> >> >> thanks and best regards >> > -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To unsubscribe from this group and stop receiving emails from it, send an email to datamapper+unsubscr...@googlegroups.com. To post to this group, send email to datamapper@googlegroups.com. Visit this group at http://groups.google.com/group/datamapper?hl=en. For more options, visit https://groups.google.com/groups/opt_out.