Class: Fiona7::TypeLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/fiona7/type_loader.rb

Defined Under Namespace

Classes: AttributeTypeHelper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj_class) ⇒ TypeLoader

Returns a new instance of TypeLoader.



24
25
26
27
28
# File 'lib/fiona7/type_loader.rb', line 24

def initialize(obj_class)
  self.obj_class    = obj_class
  self.rc_obj_class = RailsConnector::Meta::EagerLoader.instance.obj_class(Fiona7::ObjClassNameMangler.new(self.obj_class).mangle)

end

Instance Attribute Details

#obj_classObject

Returns the value of attribute obj_class.



22
23
24
# File 'lib/fiona7/type_loader.rb', line 22

def obj_class
  @obj_class
end

#rc_obj_classObject

Returns the value of attribute rc_obj_class.



22
23
24
# File 'lib/fiona7/type_loader.rb', line 22

def rc_obj_class
  @rc_obj_class
end

Instance Method Details

#load(type_definition) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fiona7/type_loader.rb', line 30

def load(type_definition)
  if Fiona7.mode == :legacy
    type_definition.add_attr('title', :string, 'title', :string)
    type_definition.add_attr('valid_from', :date, 'valid_from', :date)
    type_definition.add_attr('valid_until', :date, 'valid_until', :date)
    type_definition.add_attr('channels', :stringlist, 'channels', :stringlist)
    type_definition.add_attr('suppress_export', :enum, 'suppress_export', :enum, ['0', '1'])

    if self.rc_obj_class.obj_type == 'publication' || self.rc_obj_class.obj_type == 'document'
      type_definition.add_attr('body', :html, 'body', :html)
    elsif self.rc_obj_class.obj_type == 'image' || self.rc_obj_class.obj_type == 'generic'
      type_definition.add_attr('blob', :binary, 'blob', :binary)
    end
  end

  self.rc_obj_class.custom_attributes.each do |real_name, cms_attribute|
    next if Fiona7::Initializer::ATTRIBUTES_MAP.key?(real_name)

    # TODO: move this to a better place ~> AttributeNameDemangler
    if Fiona7.mode == :standalone
      virtual_name = real_name.sub("s_#{self.rc_obj_class.name}__", "")
    else
      virtual_name = real_name
    end

    type_helper  = AttributeTypeHelper.new(cms_attribute)
    real_type    = type_helper.real_type
    virtual_type = type_helper.virtual_type || real_type
    values       = cms_attribute.values

    type_definition.add_attr(virtual_name, virtual_type, real_name, real_type, values)
  end
end