Class: Baza::DatabaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/baza/database_model.rb

Overview

Used for link-methods in Rails apps

Instance Method Summary collapse

Constructor Details

#initialize(instance) ⇒ DatabaseModel

Returns a new instance of DatabaseModel.



3
4
5
# File 'lib/baza/database_model.rb', line 3

def initialize(instance)
  @instance = instance
end

Instance Method Details

#idObject



23
24
25
# File 'lib/baza/database_model.rb', line 23

def id
  @instance.name
end

#model_nameObject



7
8
9
# File 'lib/baza/database_model.rb', line 7

def model_name
  Baza::DatabaseModelName.new(@instance)
end

#persisted?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/baza/database_model.rb', line 11

def persisted?
  true
end

#to_paramObject



15
16
17
18
19
20
21
# File 'lib/baza/database_model.rb', line 15

def to_param
  if @instance.respond_to?(:to_param)
    @instance.try(:to_param)
  else
    @instance.name
  end
end