Class: Configuration

Inherits:
Ohm::Model
  • Object
show all
Includes:
Ohm::Callbacks, Ohm::ExtraValidations, Ohm::Timestamping, Ohm::Typecast
Defined in:
lib/noah/configurations.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) find_or_create(opts = {})



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/noah/configurations.rb', line 42

def find_or_create(opts={})
  begin
    if find(opts).first.nil?
      conf = create(opts)
    else  
      conf = find(opts).first
    end  
  rescue Exception => e
    e.message
  end
end

Instance Method Details

- (Boolean) is_new?

Returns:

  • (Boolean)


37
38
39
# File 'lib/noah/configurations.rb', line 37

def is_new?
  self.created_at == self.updated_at
end

- (Object) stash_name (protected)



56
57
58
# File 'lib/noah/configurations.rb', line 56

def stash_name
  @deleted_name = self.name
end

- (Object) to_hash



32
33
34
35
# File 'lib/noah/configurations.rb', line 32

def to_hash
  Application[application_id].nil? ? app_name=nil : app_name=Application[application_id].name
  super.merge(:name => name, :format => format, :body => body, :created_at => created_at, :updated_at => updated_at, :application => app_name)
end

- (Object) validate



23
24
25
26
27
28
29
30
# File 'lib/noah/configurations.rb', line 23

def validate
  super
  assert_present :name
  assert_present :format
  assert_present :body
  assert_present :application_id
  assert_unique [:name, :application_id]
end