From jpschewe at mtu.net Sat Jun 4 10:15:40 2011 From: jpschewe at mtu.net (Jon Schewe) Date: Sat, 04 Jun 2011 09:15:40 -0500 Subject: [ditz-talk] Question about ditz and plugins Message-ID: <4DEA3E0C.2060909@mtu.net> I'm trying to create a plugin that has a field that is validated. Using standard ruby syntax I can make sure that invalid values aren't accepted. However valid values don't get written out to the YAML file. Here's what I have so far. Any ideas what I'm doing wrong? I'm pretty new to ruby and ditz, so I wouldn't be surprised if I'm missing something basic. def self.get_allowed_priorities return ["P1", "P2", "P3", "P4", "P5"] end field :priority, :multi => false, :default => "P3", :prompt => "Specify a priority (#{Issue.get_allowed_priorities * ","})" def priority=(priority) if !Issue.get_allowed_priorities.include? priority raise Error, "Priority #{priority} is not in the list of allowed priorities (#{Issue.get_allowed_priorities * ","})" end @priority = priority end From jpschewe at mtu.net Sun Jun 5 19:52:50 2011 From: jpschewe at mtu.net (Jon Schewe) Date: Sun, 05 Jun 2011 18:52:50 -0500 Subject: [ditz-talk] Question about ditz and plugins In-Reply-To: <4DEA3E0C.2060909@mtu.net> References: <4DEA3E0C.2060909@mtu.net> Message-ID: <4DEC16D2.8080101@mtu.net> I got it working, I need to use :priority instead of "priority". Is there a way to reference the method that I'm replacing so that I don't need to duplicate the code from model.rb? def priority=(priority) if !Issue.get_allowed_priorities.include? priority raise Error, "Priority #{priority} is not in the list of allowed priorities (#{Issue.get_allowed_priorities * ","})" end # Note that note setting @priority because I've overriden the # assignment method for priority to do validation of the values. # This requires me to copy the code from the generic definition of # #{name}= from model.rb. If someone knows of a better way to do this, # please change it. changed! @serialized_values.delete :priority @values[:priority] = priority end On 06/04/2011 09:15 AM, Jon Schewe wrote: > I'm trying to create a plugin that has a field that is validated. Using > standard ruby syntax I can make sure that invalid values aren't > accepted. However valid values don't get written out to the YAML file. > > Here's what I have so far. Any ideas what I'm doing wrong? I'm pretty > new to ruby and ditz, so I wouldn't be surprised if I'm missing > something basic. > > def self.get_allowed_priorities > return ["P1", "P2", "P3", "P4", "P5"] > end > > field :priority, :multi => false, :default => "P3", :prompt => "Specify > a priority (#{Issue.get_allowed_priorities * ","})" > > def priority=(priority) > if !Issue.get_allowed_priorities.include? priority > raise Error, "Priority #{priority} is not in the list of allowed > priorities (#{Issue.get_allowed_priorities * ","})" > end > @priority = priority > end > > _______________________________________________ > ditz-talk mailing list > ditz-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ditz-talk From jpschewe at mtu.net Tue Jun 7 22:39:34 2011 From: jpschewe at mtu.net (Jon Schewe) Date: Tue, 07 Jun 2011 21:39:34 -0500 Subject: [ditz-talk] Question about plugins and build_args Message-ID: <4DEEE0E6.20206@mtu.net> I see the method build_args in Operator is used to list the valid values for certain types. Is it possible for a plugin to introduce a new type and then have the types possible values added to the logic in build_args? Jon From jpschewe at mtu.net Tue Jun 7 23:12:10 2011 From: jpschewe at mtu.net (Jon Schewe) Date: Tue, 07 Jun 2011 22:12:10 -0500 Subject: [ditz-talk] Question about plugins and build_args In-Reply-To: <4DEEE0E6.20206@mtu.net> References: <4DEEE0E6.20206@mtu.net> Message-ID: <4DEEE88A.8090203@mtu.net> On 06/07/2011 09:39 PM, Jon Schewe wrote: > I see the method build_args in Operator is used to list the valid values > for certain types. Is it possible for a plugin to introduce a new type > and then have the types possible values added to the logic in build_args? > I figured it out with alias_method just after I sent this. Haven't quite figured out how to use this to override "{name}=" though.