Class: Application
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Application
- 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.
end
add_index :applications, :internal_identifier, :name => ‘applications_internal_identifier_idx’
Direct Known Subclasses
Class Method Summary collapse
- .allows_business_modules ⇒ Object
- .apps ⇒ Object
- .desktop_applications ⇒ Object (also: tools)
- .generate_unique_iid(name) ⇒ Object
- .iid(internal_identifier) ⇒ Object
-
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation
(also: scope_by_dba)
scope by dba organization.
-
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party.
Instance Method Summary collapse
Class Method Details
.allows_business_modules ⇒ Object
85 86 87 |
# File 'app/models/application.rb', line 85 def allows_business_modules where('allow_business_modules = ?', true) end |
.apps ⇒ Object
48 49 50 |
# File 'app/models/application.rb', line 48 def apps where('type is null') end |
.desktop_applications ⇒ Object 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
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
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, ={}) 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 [:role_types] statement = statement.where("#{table_alias}.role_type_id" => RoleType.find_child_role_types([:role_types])) end statement end |
Instance Method Details
#to_data_hash ⇒ Object
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 |