Class: RailsConnector::ObjClass

Inherits:
AbstractModel
  • Object
show all
Defined in:
app/models/rails_connector/obj_class.rb

Overview

This class is used to read out the custom attributes, mandatory attributes and titles of an Obj. Warning: Dependent on the setup of your DB replication, most tables with meta information will not be available on your live system!

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_name(*args) ⇒ Object

Convenience method for find_by_obj_class_name



81
82
83
# File 'app/models/rails_connector/obj_class.rb', line 81

def self.find_by_name(*args)
  self.find_by_obj_class_name(*args)
end

.read_blob_data(name) ⇒ Object

Reads a whole bunch of data, where only some of it is useful in a Rails application: attributeGroups, availableBlobEditors, bodyTemplateName, canCreateNewsItems, completionCheck, mandatoryAttributes, presetAttributes, recordSetCallback, titles, validSubObjClassCheck, workflowModification



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/rails_connector/obj_class.rb', line 91

def self.read_blob_data(name) #:nodoc:
  blob = RailsConnector::Meta.hello_im_rails_and_im_retarted_so_please_be_patient do            # these queries really pollute our logs!
    blob_name = if RailsConnector::BlobMapping.exists?
      RailsConnector::BlobMapping.get_fingerprint("#{name}.jsonObjClassDict")
    else
      "#{name}.jsonObjClassDict"
    end

    RailsConnector::Blob.find_without_excluded_blob_data(blob_name)
  end

  return {} unless blob && blob.blob_data?

  JSON.parse(blob.blob_data)
end

Instance Method Details

#can_create_news_items?Boolean

returns channel feature is_activate?

Returns:

  • (Boolean)


29
30
31
32
# File 'app/models/rails_connector/obj_class.rb', line 29

def can_create_news_items?
  load_blob_data
  @blob_data['canCreateNewsItems'].to_i != 0
end

#custom_attribute?(attr) ⇒ Boolean

Returns true, if the Obj Class has an attribute of the given name.

Returns:

  • (Boolean)


58
59
60
# File 'app/models/rails_connector/obj_class.rb', line 58

def custom_attribute?(attr)
  self.custom_attributes.key?(attr)
end

#custom_attributesObject

Returns the custom attributes in the form of a Hash.



47
48
49
50
51
52
53
54
55
# File 'app/models/rails_connector/obj_class.rb', line 47

def custom_attributes
  # return the cached data
  return @custom_attributes if @custom_attributes

  # create a Hash (with indifferent access) out of an Array of ActiveRecord objects
  @custom_attributes = self.custom_attributes_raw.map do |attr|
    {attr.attribute_name => attr}
  end.reduce(HashWithIndifferentAccess.new, &:merge)
end

#has_custom_ruby_class?Boolean

Returns true, if a custom Ruby class exists.

Returns:

  • (Boolean)


41
42
43
44
# File 'app/models/rails_connector/obj_class.rb', line 41

def has_custom_ruby_class?
  self.ruby_class.present? && self.ruby_class != RailsConnector::AbstractObj &&
      self.ruby_class.ancestors.include?(RailsConnector::AbstractObj)
end

#mandatory_attribute?(attr) ⇒ Boolean

Returns true, if the file format has an mandatory attribute of the given name.

Returns:

  • (Boolean)


76
77
78
# File 'app/models/rails_connector/obj_class.rb', line 76

def mandatory_attribute?(attr)
  self.mandatory_attribute_names.include?(attr.to_s)
end

#mandatory_attribute_names(options = {}) ⇒ Object

Returns an Array of String of all mandatory attributes found for this ObjClass, no matter if it is a custom or built-in attribute. Built-in attributes are underscored (valid_from, not validFrom). Possible options are:

:only_custom_attributes

Return only custom attributes, omit

built-in attributes like content_type or valid_from.



68
69
70
71
72
73
# File 'app/models/rails_connector/obj_class.rb', line 68

def mandatory_attribute_names(options = {})
  only_custom_attributes ||= options[:only_custom_attributes] || false
  build_mandatory_attribute_arrays
  return @mandatory_custom_attributes if only_custom_attributes
  @mandatory_attributes
end

#ruby_classObject

Returns the custom Ruby class or RailsConnector::AbstractObj.



35
36
37
38
# File 'app/models/rails_connector/obj_class.rb', line 35

def ruby_class
  # this must be the same algorithm that the rest of the RailsConnector uses!
  RailsConnector::AbstractObj.compute_type(self.name)
end

#title(language) ⇒ Object

Returns the title of the file format or nil, if it was not set.



18
19
20
# File 'app/models/rails_connector/obj_class.rb', line 18

def title(language)
  self.titles[language.to_s].presence
end

#titlesObject

Returns all titles as a Hash.



23
24
25
26
# File 'app/models/rails_connector/obj_class.rb', line 23

def titles
  load_blob_data
  @blob_data['titles'] || {}
end