Skip to content

Commit

Permalink
Merge pull request #7980 from eduardoj/move_methods_to_private
Browse files Browse the repository at this point in the history
Move methods only used in its own class to private
  • Loading branch information
vpereira committed Jul 29, 2019
2 parents b7d3502 + 19739c5 commit dcfdd3e
Show file tree
Hide file tree
Showing 16 changed files with 694 additions and 670 deletions.
11 changes: 7 additions & 4 deletions src/api/app/models/architecture.rb
Expand Up @@ -23,10 +23,6 @@ class Architecture < ApplicationRecord

#### Class methods using self. (public and then private)

def discard_cache
Rails.cache.delete('archcache')
end

def self.archcache
Rails.cache.fetch('archcache') do
Architecture.all.map { |arch| [arch.name, arch] }.to_h
Expand Down Expand Up @@ -56,6 +52,13 @@ def worker
def to_s
name
end

private

def discard_cache
Rails.cache.delete('archcache')
end

#### Alias of methods
end

Expand Down
8 changes: 4 additions & 4 deletions src/api/app/models/attrib.rb
Expand Up @@ -84,10 +84,6 @@ def values_removeable?
(attrib_type.value_count && (attrib_type.value_count != values.length)) # If value_count != values.length
end

def write_container_attributes
container.write_attributes if container && !container.destroyed?
end

def update_with_associations(values = [], issues = [])
#--- update issues ---#
changed = false
Expand Down Expand Up @@ -141,6 +137,10 @@ def validate_allowed_values_for_attrib_type
value_count = attrib_type.try(:value_count)
errors[:values] << "has #{values.length} values, but only #{value_count} are allowed" if value_count && value_count != values.length
end

def write_container_attributes
container.write_attributes if container && !container.destroyed?
end
end

# == Schema Information
Expand Down
20 changes: 11 additions & 9 deletions src/api/app/models/attrib_namespace.rb
Expand Up @@ -22,6 +22,17 @@ def to_s
name
end

def update_from_xml(node)
transaction do
attrib_namespace_modifiable_bies.delete_all
# store permission settings
node.elements('modifiable_by') { |element| create_one_rule(element) }
save
end
end

private

def create_one_rule(node)
if !node['user'] && !node['group']
raise "attribute type '#{node.name}' modifiable_by element has no valid rules set"
Expand All @@ -32,15 +43,6 @@ def create_one_rule(node)
attrib_namespace_modifiable_bies << AttribNamespaceModifiableBy.new(new_rule)
end

def update_from_xml(node)
transaction do
attrib_namespace_modifiable_bies.delete_all
# store permission settings
node.elements('modifiable_by') { |element| create_one_rule(element) }
save
end
end

#### Alias of methods
end

Expand Down
46 changes: 24 additions & 22 deletions src/api/app/models/attrib_type.rb
Expand Up @@ -62,28 +62,6 @@ def fullname
"#{attrib_namespace}:#{name}"
end

def create_one_rule(node)
if node['user'].blank? && node['group'].blank? && node['role'].blank?
raise "attribute type '#{node.name}' modifiable_by element has no valid rules set"
end
new_rule = {}
new_rule[:user] = User.find_by_login!(node['user']) if node['user']
new_rule[:group] = Group.find_by_title!(node['group']) if node['group']
new_rule[:role] = Role.find_by_title!(node['role']) if node['role']
attrib_type_modifiable_bies << AttribTypeModifiableBy.new(new_rule)
end

def update_default_values(default_elements)
default_values.delete_all
position = 1
default_elements.each do |d|
d.elements('value') do |v|
default_values << AttribDefaultValue.new(value: v, position: position)
position += 1
end
end
end

def update_from_xml(xmlhash)
transaction do
# defined permissions
Expand Down Expand Up @@ -142,6 +120,30 @@ def as_json(options = nil)
end
end

private

def create_one_rule(node)
if node['user'].blank? && node['group'].blank? && node['role'].blank?
raise "attribute type '#{node.name}' modifiable_by element has no valid rules set"
end
new_rule = {}
new_rule[:user] = User.find_by_login!(node['user']) if node['user']
new_rule[:group] = Group.find_by_title!(node['group']) if node['group']
new_rule[:role] = Role.find_by_title!(node['role']) if node['role']
attrib_type_modifiable_bies << AttribTypeModifiableBy.new(new_rule)
end

def update_default_values(default_elements)
default_values.delete_all
position = 1
default_elements.each do |d|
d.elements('value') do |v|
default_values << AttribDefaultValue.new(value: v, position: position)
position += 1
end
end
end

#### Alias of methods
end

Expand Down
55 changes: 29 additions & 26 deletions src/api/app/models/binary_release.rb
Expand Up @@ -133,44 +133,19 @@ def set_release_time!
self.binary_releasetime = Time.now
end

def set_release_time
# created_at, but readable in database
self.binary_releasetime ||= Time.now
end

def update_for_product
repository.product_update_repositories.map { |i| i.product if i.product }.uniq
end

def product_medium
repository.product_medium.find_by(name: medium)
end

# esp. for docker/appliance/python-venv-rpms and friends
def medium_container
on_medium.try(:release_package)
end

# renders all values, which are used as identifier of a binary entry.
def render_attributes
attributes = { project: repository.project.name, repository: repository.name }
[:binary_name, :binary_epoch, :binary_version, :binary_release, :binary_arch, :medium].each do |key|
value = send(key)
next unless value
ekey = key.to_s.gsub(/^binary_/, '')
attributes[ekey] = value
end
attributes
end

def render_xml
builder = Nokogiri::XML::Builder.new
builder.binary(render_attributes) do |binary|
binary.operation(operation)

node = {}
node[:package] = release_package.name if release_package
node[:time] = self.binary_releasetime if self.binary_releasetime
node[:time] = binary_releasetime if binary_releasetime
node[:flavor] = flavor if flavor
binary.publish(node) unless node.empty?

Expand Down Expand Up @@ -222,6 +197,34 @@ def identical_to?(binary_hash)
(binary_id.nil? || binary_id == binary_hash['binaryid']) &&
binary_buildtime == buildtime
end

private

def product_medium
repository.product_medium.find_by(name: medium)
end

# renders all values, which are used as identifier of a binary entry.
def render_attributes
attributes = { project: repository.project.name, repository: repository.name }
[:binary_name, :binary_epoch, :binary_version, :binary_release, :binary_arch, :medium].each do |key|
value = send(key)
next unless value
ekey = key.to_s.gsub(/^binary_/, '')
attributes[ekey] = value
end
attributes
end

def set_release_time
# created_at, but readable in database
self.binary_releasetime ||= Time.now
end

def update_for_product
repository.product_update_repositories.map { |i| i.product if i.product }.uniq
end

#### Alias of methods
end

Expand Down

0 comments on commit dcfdd3e

Please sign in to comment.