Class: Noah::Ephemeral

Inherits:
Model
  • Object
show all
Includes:
EphemeralValidations, Linkable, Taggable
Defined in:
lib/noah/models/ephemerals.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Linkable

included, #link!, #unlink!

Methods included from Taggable

included, #tag!, #untag!

Methods included from EphemeralValidations

#assert_not_reserved

Methods inherited from Model

inherited

Class Method Details

.find_or_create(opts = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/noah/models/ephemerals.rb', line 29

def find_or_create(opts = {})
  begin
    path, data = opts[:path], opts[:data]
    find(:path => path).first.nil? ? (obj = new(:path => path)) : (obj = find(:path => path).first)
    obj.data = data
    if obj.valid?
      obj.save
    end
    obj
  rescue Exception => e
    e.message
  end
end

Instance Method Details

#nameObject



19
20
21
# File 'lib/noah/models/ephemerals.rb', line 19

def name
  @name = path
end

#to_hashObject



23
24
25
26
# File 'lib/noah/models/ephemerals.rb', line 23

def to_hash
  h = {:path => path, :data => data, :created_at => created_at, :updated_at => updated_at}
  super.merge(h)
end

#validateObject



12
13
14
15
16
17
# File 'lib/noah/models/ephemerals.rb', line 12

def validate
  super
  assert_present :path
  assert_unique :path
  assert_not_reserved
end