Sha256: d8f86e1d48b290ff5928803944376aeb0614aa713c4a270558b35c32b9b9c96b

Contents?: true

Size: 683 Bytes

Versions: 49

Compression:

Stored size: 683 Bytes

Contents

class Story < Ticket
  has_one :story_detail, foreign_key: "ticket_id", dependent: :destroy

  validates :who, :what, presence: true

  after_save do 
    story_detail.save if story_detail.changed?
  end

  [:who, :what, :why].each do |method|
    define_method(method) do |*args|
      return nil unless story_detail
      story_detail.send(method, *args)
    end

    define_method("#{method}=") do |*args|
      build_story_detail unless story_detail
      story_detail.send("#{method}=", *args)
    end
  end

  def title
    return super unless who.present? && what.present?
    title = "#{who} wants to #{what}"
    title += ", so: #{why}" if why.present?

    title
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
tawork-0.0.50 app/models/story.rb
tawork-0.0.49 app/models/story.rb
tawork-0.0.48 app/models/story.rb
tawork-0.0.47 app/models/story.rb
tawork-0.0.46 app/models/story.rb
tawork-0.0.45 app/models/story.rb
tawork-0.0.44 app/models/story.rb
tawork-0.0.43 app/models/story.rb
tawork-0.0.42 app/models/story.rb
tawork-0.0.41 app/models/story.rb
tawork-0.0.40 app/models/story.rb
tawork-0.0.39 app/models/story.rb
tawork-0.0.38 app/models/story.rb
tawork-0.0.37 app/models/story.rb
tawork-0.0.36 app/models/story.rb
tawork-0.0.35 app/models/story.rb
tawork-0.0.34 app/models/story.rb
tawork-0.0.33 app/models/story.rb
tawork-0.0.31 app/models/story.rb
tawork-0.0.30 app/models/story.rb