Skip to content

Commit

Permalink
Refactor container and image matching in providers
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad committed Jul 23, 2014
1 parent 2d3763b commit 1aac671
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 14 additions & 10 deletions providers/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,34 @@ def container_matches?(ps)
end

def container_command_matches_if_exists?(command)
return true if new_resource.command.nil?
# try the exact command but also the command with the ' and " stripped out, since docker will
# sometimes strip out quotes.
subcommand = new_resource.command.gsub(/['"]/, '')
command.include?(new_resource.command) || command.include?(subcommand)
if new_resource.command
# try the exact command but also the command with the ' and " stripped out, since docker will
# sometimes strip out quotes.
subcommand = new_resource.command.gsub(/['"]/, '')
command.include?(new_resource.command) || command.include?(subcommand)
else
true
end
end

def container_id_matches?(id)
return false unless id
return false unless id && new_resource.id
id.start_with?(new_resource.id)
end

def container_image_matches?(image)
return false unless image
return false unless image && new_resource.image
image.include?(new_resource.image)
end

def container_name_matches?(names)
return false unless names
new_resource.container_name if names.split(',').include?(new_resource.container_name)
return false unless names && new_resource.container_name
return true if names.split(',').include?(new_resource.container_name)
false
end

def container_name_matches_if_exists?(names)
return false if new_resource.container_name && new_resource.container_name != names
return false if new_resource.container_name && names.split(',').include?(new_resource.container_name)
true
end

Expand Down
2 changes: 2 additions & 0 deletions providers/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ def image_and_tag_arg
end

def image_id_matches?(id)
return false unless id && new_resource.id
id.start_with?(new_resource.id)
end

def image_name_matches?(name)
return false unless name && new_resource.image_name
name.include?(new_resource.image_name)
end

Expand Down

0 comments on commit 1aac671

Please sign in to comment.