Class: Noah::Application

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Linkable

included, #link!, #unlink!

Methods included from Taggable

included, #tag!, #untag!

Methods inherited from Model

inherited

Class Method Details

.find_or_create(opts = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/noah/models/applications.rb', line 28

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

Instance Method Details

#to_hashObject



18
19
20
21
22
23
24
25
# File 'lib/noah/models/applications.rb', line 18

def to_hash
  cfg_hash = Hash.new
  configurations.sort.each do |cfg|
    cfg_hash["#{cfg.name}"] = {:format => cfg.to_hash[:format], :body => cfg.to_hash[:body]}
  end
  res_hash = {:name => name, :created_at => created_at, :updated_at => updated_at, :configurations => cfg_hash}
  super.merge(res_hash)
end

#validateObject



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

def validate
  super
  assert_present :name
  assert_unique :name
end