Skip to content

Commit

Permalink
Merge pull request #16399 from alexander-demichev/delete-conditions
Browse files Browse the repository at this point in the history
Replace conditions with scope
  • Loading branch information
gtanzillo authored Nov 29, 2017
2 parents 363438e + 7c377bf commit 894bbfb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
6 changes: 2 additions & 4 deletions app/models/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ class Filesystem < ApplicationRecord
virtual_column :contents, :type => :string, :uses => {:binary_blob => :binary_blob_parts}
virtual_column :contents_available, :type => :boolean, :uses => :binary_blob

scope :host_service_group_filesystems, ->(host_service_group_id) { where(:host_service_group_id => host_service_group_id) }

UTF_16BE_BOM = [254, 255].freeze
UTF_16LE_BOM = [255, 254].freeze

def self.host_service_group_condition(host_service_group_id)
arel_table[:host_service_group_id].eq(host_service_group_id)
end

def self.add_elements(miq_set, scan_item, parent, xmlNode)
options = {}
options[:miq_set_id] = miq_set.id unless miq_set.nil?
Expand Down
22 changes: 10 additions & 12 deletions app/models/system_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ class SystemService < ApplicationRecord

serialize :dependencies, Hash

scope :running_systemd_services, -> { where(:systemd_active => 'active', :systemd_sub => 'running') }
scope :failed_systemd_services, -> { where(:systemd_active => 'failed').or(where(:systemd_sub => 'failed')) }
scope :host_service_group_systemd, ->(host_service_group_id) { where(:host_service_group_id => host_service_group_id) }
scope :host_service_group_running_systemd, lambda { |host_service_group_id|
running_systemd_services.merge(host_service_group_systemd(host_service_group_id))
}
scope :host_service_group_failed_systemd, lambda { |host_service_group_id|
failed_systemd_services.merge(host_service_group_systemd(host_service_group_id))
}

SVC_TYPES = {
# Type Display
"" => "",
Expand Down Expand Up @@ -42,18 +52,6 @@ def svc_type
SVC_TYPES[svc] || svc
end

def self.running_systemd_services_condition
arel_table[:systemd_active].eq('active').and(arel_table[:systemd_sub].eq('running'))
end

def self.failed_systemd_services_condition
arel_table[:systemd_active].eq('failed').or(arel_table[:systemd_sub].eq('failed'))
end

def self.host_service_group_condition(host_service_group_id)
arel_table[:host_service_group_id].eq(host_service_group_id)
end

def self.add_elements(parent, xmlNode)
add_missing_elements(parent, xmlNode, "services")
end
Expand Down

0 comments on commit 894bbfb

Please sign in to comment.