Class: Marty::Tag

Inherits:
Base show all
Defined in:
app/models/marty/tag.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

get_final_attrs, make_hash, make_openstruct, mcfly_pt

Methods inherited from ActiveRecord::Base

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, comment)
  o            = new
  o.comment    = comment
  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_latest1Object



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_attrsObject



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)

  # If no dt is provided (which is the usual non-testing case), we
  # use Time.now.strftime to name the posting.  This has the effect
  # of using the host's timezone. i.e. since we're in PST8PDT, names
  # will be based off of the Pacific TZ.
  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)
  # FIXME: this is really hacky. This function should not take so
  # many different types of arguments.
  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 name wasn't found, look for a matching
    # posting, then find the tag whose created_dt <= posting dt.
    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

Returns:

  • (Boolean)


38
39
40
# File 'app/models/marty/tag.rb', line 38

def isdev?
  Mcfly.is_infinity(created_dt)
end

#set_tag_nameObject



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