Class: Inform::Tag

Inherits:
Sequel::Model show all
Defined in:
lib/runtime/tag.rb

Overview

The Inform::Tag class

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sequel::Model

implicit_table_name

Methods included from InheritanceListener

included

Class Method Details

.dirtyObject

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

.statsObject

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

.tidyObject



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_createObject



61
62
63
64
# File 'lib/runtime/tag.rb', line 61

def after_create
  super
  Inform.attributes.reset
end

#after_saveObject



66
67
68
69
# File 'lib/runtime/tag.rb', line 66

def after_save
  super
  self.modified_at = Time.now.utc
end

#before_createObject



56
57
58
59
# File 'lib/runtime/tag.rb', line 56

def before_create
  self.created_at ||= Time.now
  super
end

#to_sObject Also known as: to_str



71
72
73
# File 'lib/runtime/tag.rb', line 71

def to_s
  name
end