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(posting_type, dt, comment) ⇒ Object



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

def self.do_create(posting_type, dt, comment)
  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_struct_attrsObject



40
41
42
# File 'app/models/marty/posting.rb', line 40

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

.make_name(posting_type, dt) ⇒ Object



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

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

Instance Method Details

#set_posting_nameObject



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

def set_posting_name
  self.name = self.class.make_name(posting_type, created_dt)
  true
end