Class: Marty::Tag
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
get_final_attrs, make_hash, make_openstruct, mcfly_pt
joins, old_joins
Class Method Details
.cached_find_match(dt) ⇒ Object
Performance hack for script sets – FIXME: making find_mtach cached breaks Gemini tests. Need to look into it.
82
83
84
85
|
# File 'app/models/marty/tag.rb', line 82
def self.cached_find_match(dt)
@@CACHE_FIND_BY_DT ||= {}
@@CACHE_FIND_BY_DT[dt] ||= find_match(dt)
end
|
.do_create(dt, comment) ⇒ Object
30
31
32
33
34
35
36
|
# File 'app/models/marty/tag.rb', line 30
def self.do_create(dt, )
o = new
o. =
o.created_dt = dt
o.save!
o
end
|
.find_match(dt) ⇒ Object
76
77
78
|
# File 'app/models/marty/tag.rb', line 76
def self.find_match(dt)
order('created_dt DESC').find_by('created_dt <= ?', dt)
end
|
.get_latest1 ⇒ Object
72
73
74
|
# File 'app/models/marty/tag.rb', line 72
def self.get_latest1
order('created_dt DESC').find_by("created_dt <> 'infinity'")
end
|
.get_struct_attrs ⇒ Object
9
10
11
|
# File 'app/models/marty/tag.rb', line 9
def self.get_struct_attrs
self.struct_attrs ||= super + ['id', 'created_dt']
end
|
.make_name(dt) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'app/models/marty/tag.rb', line 13
def self.make_name(dt)
return 'DEV' if Mcfly.is_infinity(dt)
dt ||= Time.zone.now
dt.strftime('%Y%m%d-%H%M')
end
|
.map_to_tag(tag_id) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/models/marty/tag.rb', line 42
def self.map_to_tag(tag_id)
case tag_id
when Integer, /\A[0-9]+\z/
tag = find_by(id: tag_id)
when String
tag = find_by(name: tag_id)
if !tag
cdt = Marty::Posting.where(name: tag_id).pluck('created_dt').first
tag = find_match(Mcfly.normalize_infinity(cdt)) if cdt
end
when nil
tag = get_latest1
else
tag = tag_id
end
raise "bad tag identifier #{tag_id.inspect}" unless tag.is_a?(Marty::Tag)
tag
end
|
Instance Method Details
#isdev? ⇒ Boolean
38
39
40
|
# File 'app/models/marty/tag.rb', line 38
def isdev?
Mcfly.is_infinity(created_dt)
end
|
#set_tag_name ⇒ Object
25
26
27
28
|
# File 'app/models/marty/tag.rb', line 25
def set_tag_name
self.name = self.class.make_name(created_dt)
true
end
|