Class: Geert::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/geert/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Model

Returns a new instance of Model.



7
8
9
# File 'lib/geert/model.rb', line 7

def initialize(model)
  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/geert/model.rb', line 5

def model
  @model
end

Instance Method Details

#associationsObject



23
24
25
# File 'lib/geert/model.rb', line 23

def associations
  @associations ||= reflections.map { |reflection| Association.new(reflection, self) }
end

#columns_hash(*args) ⇒ Object



31
32
33
# File 'lib/geert/model.rb', line 31

def columns_hash(*args)
  model.columns_hash(*args)
end

#migrationObject



19
20
21
# File 'lib/geert/model.rb', line 19

def migration
  associations.map(&:migration).compact.sort if usable?
end

#outputObject



15
16
17
# File 'lib/geert/model.rb', line 15

def output
  output_string if usable? && association_output.any?
end

#table_nameObject



27
28
29
# File 'lib/geert/model.rb', line 27

def table_name
  model.table_name
end

#usable?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/geert/model.rb', line 11

def usable?
  activerecord? && reflections.any?
end