Class: Marty::Posting

Inherits:
Base show all
Defined in:
app/models/marty/posting.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

.do_create(type_name, dt, comment) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/marty/posting.rb', line 30

def self.do_create(type_name, dt, comment)
  posting_type = Marty::PostingType.find_by_name(type_name)

  raise "unknown posting type #{name}" unless posting_type

  o              = new
  o.posting_type = posting_type
  o.comment      = comment
  o.created_dt   = dt
  o.save!
  o
end

.get_latest(limit, _is_test = nil) ⇒ Object



70
71
72
73
74
75
# File 'app/models/marty/posting.rb', line 70

def self.get_latest(limit, _is_test = nil)
  # IMPORTANT: is_test arg is ignored (KEEP for backward compat.)

  q = where("created_dt <> 'infinity'").
     order('created_dt DESC').limit(limit)
end

.get_struct_attrsObject



43
44
45
# File 'app/models/marty/posting.rb', line 43

def self.get_struct_attrs
  self.struct_attrs ||= super + ['created_dt', 'name']
end

.make_name(posting_type, dt) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/marty/posting.rb', line 10

def self.make_name(posting_type, dt)
  return 'NOW' if Mcfly.is_infinity(dt)

  return unless posting_type

  # 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.now
  "#{posting_type.name}-#{dt.strftime('%Y%m%d-%H%M')}"
end

Instance Method Details

#set_posting_nameObject



24
25
26
27
28
# File 'app/models/marty/posting.rb', line 24

def set_posting_name
  posting_type = Marty::PostingType.find_by_id(posting_type_id)
  self.name = self.class.make_name(posting_type, created_dt)
  true
end