Class: Inform::Tag
- Inherits:
-
Sequel::Model
- #Object
- Object
- Sequel::Model
- Inform::Tag
- Defined in:
- lib/story_teller/inform/relational/tag.rb
Overview
class Tag
Class Method Summary collapse
-
.dirty ⇒ Object
rubocop: disable Style/FormatStringToken.
-
.stats ⇒ Object
rubocop: disable Style/FormatStringToken.
- .tidy ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #after_create ⇒ Object
- #after_save ⇒ Object
- #before_create ⇒ Object
- #to_s ⇒ Object (also: #to_str)
Methods inherited from Sequel::Model
Methods included from StoryTeller::InheritanceListener
Class Method Details
.dirty ⇒ Object
rubocop: disable Style/FormatStringToken
91 92 93 94 95 96 97 98 |
# File 'lib/story_teller/inform/relational/tag.rb', line 91 def self.dirty results = db.fetch %(select a.id, a.name from tag a group by a.id, a.name having ((select count(b.id) from tagged b where b.tag_id = a.id) = 0)) return nil if results.empty? s = [format('%5s %20s', *results.first.keys)] s.concat(results.collect { |row| format('%5d %20s', *row.values) }) s.join("\n") end |
.stats ⇒ Object
rubocop: disable Style/FormatStringToken
102 103 104 105 106 107 108 109 |
# File 'lib/story_teller/inform/relational/tag.rb', line 102 def self.stats results = db.fetch %(select a.*, count(a.id) as "number tagged" from tag a, tagged b where b.tag_id = a.id group by a.id, a.name) return nil if results.empty? s = [format('%5s %20s %15s', *results.first.keys)] s.concat(results.collect { |row| format('%5d %20s %15s', *row.values) }) s.join("\n") end |
.tidy ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/story_teller/inform/relational/tag.rb', line 81 def self.tidy db << %(delete from tag where id in (select a.id from tag a group by a.id, a.name having ((select count(b.id) from tagged b where b.tag_id = a.id) = 0))) Inform.attributes.reset return nil end |
Instance Method Details
#<=>(other) ⇒ Object
77 78 79 |
# File 'lib/story_teller/inform/relational/tag.rb', line 77 def <=>(other) self.name <=> other.name end |
#after_create ⇒ Object
62 63 64 65 |
# File 'lib/story_teller/inform/relational/tag.rb', line 62 def after_create super Inform.attributes.reset end |
#after_save ⇒ Object
67 68 69 70 |
# File 'lib/story_teller/inform/relational/tag.rb', line 67 def after_save super self.modified_at = Time.now.utc end |
#before_create ⇒ Object
57 58 59 60 |
# File 'lib/story_teller/inform/relational/tag.rb', line 57 def before_create self.created_at ||= Time.now super end |
#to_s ⇒ Object Also known as: to_str
72 73 74 |
# File 'lib/story_teller/inform/relational/tag.rb', line 72 def to_s name end |