[ditz-talk] Question about ditz and plugins

Jon Schewe jpschewe at mtu.net
Sun Jun 5 19:52:50 EDT 2011


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


More information about the ditz-talk mailing list