Class: FeideeUtils::Category

Inherits:
Record
  • Object
show all
Includes:
Mixins::ParentAndPath, Mixins::Type
Defined in:
lib/feidee_utils/category.rb

Constant Summary collapse

ProjectRootTypeCode =
2
FieldMappings =
{
  name:                   "name",
  parent_poid:            "parentCategoryPOID",
  raw_path:               "path",
  depth:                  "depth",
  raw_type:               "type",
  ordered:                "ordered",
}.freeze
IgnoredFields =
[
  "userTradingEntityPOID", # Foreign key to t_user.
  "_tempIconName",         # Icon name in the app
  "usedCount",             # Always 0.
  "clientID",              # Always equal to poid.
].freeze

Constants included from Mixins::ParentAndPath

Mixins::ParentAndPath::NullPOID

Constants included from Record::Utils

Record::Utils::AssumedTimezone

Instance Attribute Summary

Attributes included from Record::Namespaced::ClassMethods

#child_classes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Type

included, #type

Methods included from Mixins::ParentAndPath

#has_parent?, #parent, #path, #validate_depth_integrity, #validate_one_level_path_integrity, #validate_path_integrity_hard

Methods inherited from Record

generate_subclasses, #initialize

Methods included from Record::Computed::ClassMethods

#computed

Methods included from Record::Persistent::ClassMethods

#all, #column_names, #columns, #find, #find_by_id

Methods included from Record::Accessors

#last_update_time, #poid

Constructor Details

This class inherits a constructor from FeideeUtils::Record

Class Method Details

.validate_global_integrityObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/feidee_utils/category.rb', line 22

def self.validate_global_integrity
  if TypeEnum[ProjectRootTypeCode] != :project_root
    raise "The type code of project root has been changed," +
      " please update the code."
  end

  rows = self.database.execute <<-SQL
    SELECT #{id_field_name}, #{FieldMappings[:name]} FROM #{table_name}
    WHERE #{FieldMappings[:raw_type]}=#{ProjectRootTypeCode};
  SQL

  if rows.length > 1
    poids = rows.map do |row| row[0] end
    raise "More than one category have type project_root." +
      " IDs are #{poids.inspect}."
  elsif rows.length == 1
    category_name = rows[0][1]
    if category_name != "projectRoot" and category_name != "root"
      raise "Category #{category_name} has type project_root." +
        " ID: #{rows[0][0]}."
    end
  end
end

Instance Method Details

#to_sObject



70
71
72
# File 'lib/feidee_utils/category.rb', line 70

def to_s
  "#{name} (Category/#{poid})"
end

#validate_integrityObject



10
11
12
13
14
15
16
17
18
# File 'lib/feidee_utils/category.rb', line 10

def validate_integrity
  validate_depth_integrity
  validate_one_level_path_integrity
  unless column("usedCount") == 0
    raise "Category usedCount should always be 0, " +
      "but it's #{column("usedCount")}.\n" +
      inspect
  end
end