Class: Noah::Configuration
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/noah/models/configurations.rb', line 45
def find_or_create(opts={})
begin
find(:name => opts[:name]).first.nil? ? (obj = new(opts)) : (obj = find(:name => opts[:name]).first)
if obj.valid? && obj.new?
obj.save
else
obj.format = opts[:format]
obj.body = opts[:body]
obj.save if obj.valid?
end
obj
rescue Exception => e
e.message
end
end
|
Instance Method Details
#affected_applications ⇒ Object
40
41
42
|
# File 'lib/noah/models/configurations.rb', line 40
def affected_applications
@affected_applications
end
|
#delete ⇒ Object
Because we’re not doing a 2-way relationship we need to clean up any applications that use this configuration ourself
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/noah/models/configurations.rb', line 29
def delete
@affected_applications = Array.new
Noah::Application.all.each do |app|
if app.configurations.member?(self)
app.configurations.delete(self)
@affected_applications << app.name
end
end
super
end
|
#to_hash ⇒ Object
22
23
24
|
# File 'lib/noah/models/configurations.rb', line 22
def to_hash
super.merge(:name => name, :format => format, :body => body, :created_at => created_at, :updated_at => updated_at)
end
|
#validate ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/noah/models/configurations.rb', line 14
def validate
super
assert_present :name
assert_present :format
assert_present :body
assert_unique :name
end
|