14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/models/notches/event.rb', line 14
def self.log(attributes)
event = self.new
event.transaction do
Rails.logger.info("[Notches] Tracking #{attributes.inspect} at #{Date.today} #{Time.now}")
now = Time.zone.now
event.name = Notches::Name.find_or_create_by(name: attributes[:name])
event.scope = Notches::Scope.find_or_create_by(scope_attributes_for(attributes[:scope]))
event.date = Notches::Date.find_or_create_by(date: now.to_date)
event.time = Notches::Time.find_or_create_by_time(now)
begin
event.save!
rescue
Rails.logger.info "Skipping non-unique event"
end
end
event
end
|