Class: Templet::Viewer::MetaModel

Inherits:
Struct
  • Object
show all
Defined in:
app/helpers/templet/viewer/meta_model.rb,
lib/generators/templet/templates/core/templet/viewer/meta_model.rb

Overview

Model introspection

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#model_protoObject

Returns the value of attribute model_proto

Returns:

  • (Object)

    the current value of model_proto



5
6
7
# File 'app/helpers/templet/viewer/meta_model.rb', line 5

def model_proto
  @model_proto
end

Instance Method Details

#field_infoObject



39
40
41
# File 'app/helpers/templet/viewer/meta_model.rb', line 39

def field_info
  model_class.content_columns
end

#input(name) ⇒ Object



29
30
31
32
33
# File 'app/helpers/templet/viewer/meta_model.rb', line 29

def input(name)
  type = type(name)

  inputs[type] or type
end

#input_namesObject



17
18
19
# File 'app/helpers/templet/viewer/meta_model.rb', line 17

def input_names
  listing_names
end

#inputsObject



35
36
37
# File 'app/helpers/templet/viewer/meta_model.rb', line 35

def inputs
  { string: :text, text: :text_area, boolean: :check_box, integer: :text }
end

#listing_namesObject



11
12
13
14
15
# File 'app/helpers/templet/viewer/meta_model.rb', line 11

def listing_names
  names.reject do |name|
    %i(id created_at updated_at).include?(name) or name.to_s =~ /_id$/
  end
end

#namesObject



6
7
8
9
# File 'app/helpers/templet/viewer/meta_model.rb', line 6

def names
  #dictionary {|column| column.name.to_sym }
  field_info.map(&:name).map(&:to_sym)
end

#type(name) ⇒ Object



21
22
23
# File 'app/helpers/templet/viewer/meta_model.rb', line 21

def type(name)
  (@types ||= types)[name]
end

#typesObject



25
26
27
# File 'app/helpers/templet/viewer/meta_model.rb', line 25

def types
  dictionary &:type
end