Class: Application

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/application.rb

Overview

create_table :applications do |t|

t.column :description, :string
t.column :icon, :string
t.column :internal_identifier, :string
t.column :type, :string
t.column :can_delete, :boolean, :default => true

t.timestamps

end

add_index :applications, :internal_identifier, :name => ‘applications_internal_identifier_idx’

Direct Known Subclasses

DesktopApplication

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allows_business_modulesObject



85
86
87
# File 'app/models/application.rb', line 85

def allows_business_modules
  where('allow_business_modules = ?', true)
end

.appsObject



48
49
50
# File 'app/models/application.rb', line 48

def apps
  where('type is null')
end

.desktop_applicationsObject Also known as: tools



89
90
91
# File 'app/models/application.rb', line 89

def desktop_applications
  where('type = ?', 'DesktopApplication')
end

.generate_unique_iid(name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/application.rb', line 29

def generate_unique_iid(name)
  iid = name.to_iid

  iid_exists = true
  iid_test = iid
  iid_counter = 1
  while iid_exists
    if Application.where(internal_identifier: iid_test).first
      iid_test = "#{iid}_#{iid_counter}"
      iid_counter += 1
    else
      iid_exists = false
      iid = iid_test
    end
  end

  iid
end

.iid(internal_identifier) ⇒ Object



25
26
27
# File 'app/models/application.rb', line 25

def iid(internal_identifier)
  find_by_internal_identifier(internal_identifier)
end

.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation Also known as: scope_by_dba

scope by dba organization

Parameters:

  • dba_organization (Party)

    dba organization to scope by

Returns:

  • (ActiveRecord::Relation)


57
58
59
# File 'app/models/application.rb', line 57

def scope_by_dba_organization(dba_organization)
  scope_by_party(dba_organization, {role_types: [RoleType.iid('dba_org')]})
end

.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation

scope by party

or an array of Party ids

Parameters:

  • party (Integer | Party | Array)

    either a id of Party record, a Party record, an array of Party records

  • options (Hash) (defaults to: {})

    options to apply to this scope

Options Hash (options):

  • :role_types (Array)

    role types to include in the scope

Returns:

  • (ActiveRecord::Relation)


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/application.rb', line 71

def scope_by_party(party, options={})
  table_alias = String.random

  statement = joins("inner join entity_party_roles as \"#{table_alias}\" on \"#{table_alias}\".entity_record_id = applications.id
                     and \"#{table_alias}\".entity_record_type = 'Application'")
  .where("#{table_alias}.party_id" => party).uniq

  if options[:role_types]
    statement = statement.where("#{table_alias}.role_type_id" => RoleType.find_child_role_types(options[:role_types]))
  end

  statement
end

Instance Method Details

#to_data_hashObject



96
97
98
99
100
101
102
103
# File 'app/models/application.rb', line 96

def to_data_hash
  to_hash(only: [:id,
                 :description,
                 :internal_identifier,
                 :icon,
                 :created_at,
                 :updated_at])
end