Class: Inform::Tag
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Inform::Tag
- Defined in:
- lib/runtime/tag.rb
Overview
The Inform::Tag class
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 InheritanceListener
Class Method Details
.dirty ⇒ Object
rubocop: disable Style/FormatStringToken
90 91 92 93 94 95 96 97 |
# File 'lib/runtime/tag.rb', line 90 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
101 102 103 104 105 106 107 108 |
# File 'lib/runtime/tag.rb', line 101 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
80 81 82 83 84 85 86 87 |
# File 'lib/runtime/tag.rb', line 80 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
76 77 78 |
# File 'lib/runtime/tag.rb', line 76 def <=>(other) self.name <=> other.name end |
#after_create ⇒ Object
61 62 63 64 |
# File 'lib/runtime/tag.rb', line 61 def after_create super Inform.attributes.reset end |
#after_save ⇒ Object
66 67 68 69 |
# File 'lib/runtime/tag.rb', line 66 def after_save super self.modified_at = Time.now.utc end |
#before_create ⇒ Object
56 57 58 59 |
# File 'lib/runtime/tag.rb', line 56 def before_create self.created_at ||= Time.now super end |
#to_s ⇒ Object Also known as: to_str
71 72 73 |
# File 'lib/runtime/tag.rb', line 71 def to_s name end |