ticketable 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
1
  class CreateTickets < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :tickets do |t|
4
- t.references :<%= name.singularize.downcase %>
4
+ t.references :<%= name.singularize.downcase %>, null: false
5
+ t.string :action
5
6
  t.integer :status, default: 0
6
7
  t.text :content
7
8
  t.references :ticketable, polymorphic: true
@@ -1,10 +1,14 @@
1
1
  class Ticket < ActiveRecord::Base
2
2
  belongs_to :<%= name.singularize.downcase %>
3
3
  belongs_to :ticketable, polymorphic: true
4
- attr_accessible :status, :content, :ticketable
4
+ attr_accessible :status, :content, :ticketable, :action
5
5
  attr_accessible :<%= name.singularize.downcase %>_id
6
6
 
7
- [:open, :in_progress, :close].each_with_index do |status, i|
7
+ validates_presence_of :<%= name.singularize.downcase %>_id
8
+
9
+ STATUS = [:open, :in_progress, :close]
10
+
11
+ Ticket::STATUS.each_with_index do |status, i|
8
12
  define_method "is_#{status.to_s}?" do
9
13
  self.status == i
10
14
  end
@@ -15,4 +19,12 @@ class Ticket < ActiveRecord::Base
15
19
 
16
20
  scope status.to_s.pluralize.to_sym, -> { where(status: i) }
17
21
  end
22
+
23
+ def title
24
+ I18n.t "ticketable.#{ticketable_type}.#{action}", ressource: ticketable, by: <%= name.singularize.downcase %>
25
+ end
26
+
27
+ def as_json options={}
28
+ super(options).merge! title: title
29
+ end
18
30
  end
@@ -1,3 +1,3 @@
1
1
  module Ticketable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ticketable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Make every ressource as a ticket with a status and a brief
15
15
  email: