Class: Card
- Defined in:
- lib/card/env.rb,
lib/card.rb,
lib/card/act.rb,
lib/card/set.rb,
lib/card/auth.rb,
lib/card/name.rb,
lib/card/chunk.rb,
lib/card/action.rb,
lib/card/change.rb,
lib/card/format.rb,
lib/card/loader.rb,
lib/card/mailer.rb,
lib/card/content.rb,
lib/card/codename.rb,
lib/card/exceptions.rb,
lib/card/set_pattern.rb,
lib/card/query/card_spec.rb
Overview
you could make the case that Card::Chunk should be Card::Content::Chunk…
Defined Under Namespace
Modules: Auth, Chunk, Diff, Env, Loader, Set Classes: Abort, Act, Action, BadQuery, Change, Codename, Content, Error, Format, Mailer, Name, Oops, PermissionDenied, Query, Reference, SetPattern
Constant Summary collapse
- TRACKED_FIELDS =
%w(name type_id db_content trash)
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#comment_author ⇒ Object
Returns the value of attribute comment_author.
-
#current_act ⇒ Object
Returns the value of attribute current_act.
-
#current_action ⇒ Object
Returns the value of attribute current_action.
-
#follower_stash ⇒ Object
Returns the value of attribute follower_stash.
-
#last_action_id_before_edit ⇒ Object
Returns the value of attribute last_action_id_before_edit.
-
#supercard ⇒ Object
Returns the value of attribute supercard.
-
#update_referencers ⇒ Object
Returns the value of attribute update_referencers.
Class Method Summary collapse
Instance Method Summary collapse
- #delete_old_actions ⇒ Object
-
#find_action_by_params(args) ⇒ Object
fixme - these Card class methods should probably be in a set module.
- #nth_action(index) ⇒ Object
- #revision(action) ⇒ Object
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
26 27 28 |
# File 'lib/card.rb', line 26 def action @action end |
#comment ⇒ Object
Returns the value of attribute comment.
26 27 28 |
# File 'lib/card.rb', line 26 def comment @comment end |
#comment_author ⇒ Object
Returns the value of attribute comment_author.
26 27 28 |
# File 'lib/card.rb', line 26 def end |
#current_act ⇒ Object
Returns the value of attribute current_act.
26 27 28 |
# File 'lib/card.rb', line 26 def current_act @current_act end |
#current_action ⇒ Object
Returns the value of attribute current_action.
26 27 28 |
# File 'lib/card.rb', line 26 def current_action @current_action end |
#follower_stash ⇒ Object
Returns the value of attribute follower_stash.
26 27 28 |
# File 'lib/card.rb', line 26 def follower_stash @follower_stash end |
#last_action_id_before_edit ⇒ Object
Returns the value of attribute last_action_id_before_edit.
26 27 28 |
# File 'lib/card.rb', line 26 def last_action_id_before_edit @last_action_id_before_edit end |
#supercard ⇒ Object
Returns the value of attribute supercard.
26 27 28 |
# File 'lib/card.rb', line 26 def supercard @supercard end |
#update_referencers ⇒ Object
Returns the value of attribute update_referencers.
26 27 28 |
# File 'lib/card.rb', line 26 def update_referencers @update_referencers end |
Class Method Details
.const_missing(const) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/card/codename.rb', line 58 def self.const_missing const if const.to_s =~ /^([A-Z]\S*)ID$/ and code=$1.underscore.to_sym if card_id = Codename[code] const_set const, card_id else raise "Missing codename #{code} (#{const})" end else super end end |
Instance Method Details
#delete_old_actions ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/card/action.rb', line 32 def delete_old_actions Card::TRACKED_FIELDS.each do |field| # assign previous changes on each tracked field to the last action if (not last_action.change_for(field).present?) and (last_change = last_change_on(field)) last_change = Card::Change.find(last_change.id) # last_change comes as readonly record last_change.update_attributes!(:card_action_id=>last_action_id) end end actions.where('id != ?', last_action_id ).delete_all end |
#find_action_by_params(args) ⇒ Object
fixme - these Card class methods should probably be in a set module
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/card/action.rb', line 5 def find_action_by_params args case when args[:rev] nth_action(args[:rev].to_i-1) when args[:rev_id] if action = Action.fetch(args[:rev_id]) and action.card_id == id action end end end |
#nth_action(index) ⇒ Object
16 17 18 |
# File 'lib/card/action.rb', line 16 def nth_action index Action.where("draft is not true AND card_id = #{id}").order(:id).limit(1).offset(index-1).first end |
#revision(action) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/card/action.rb', line 20 def revision action # a "revision" refers to the state of all tracked fields at the time of a given action if action.is_a? Integer action = Card::Action.fetch(action) end action and Card::TRACKED_FIELDS.inject({}) do |attr_changes, field| last_change = action.changes.find_by_field(field) || last_change_on(field, :not_after=>action) attr_changes[field.to_sym] = (last_change ? last_change.value : self[field]) attr_changes end end |