class Redirus::Worker::AddProxy::Action

Attributes

name[R]
type[R]
workers[R]

Public Class Methods

new(name, workers, type, location_props, options = {}) click to toggle source
# File lib/redirus/worker/add_proxy.rb, line 16
def initialize(name, workers, type, location_props, options = {})
  @name = name
  @workers = workers
  @type = type
  @location_properties = location_properties(location_props) || []
  @options = options
end

Public Instance Methods

execute() click to toggle source
# File lib/redirus/worker/add_proxy.rb, line 26
def execute
  File.open(config_file_path(name, type), 'w') do |file|
    erb = ERB.new(template, nil, '-')
    file.write erb.result(binding)
  end
end

Private Instance Methods

allowed?(prop) click to toggle source
# File lib/redirus/worker/add_proxy.rb, line 42
def allowed?(prop)
  config.
    allowed_properties.
    any? { |prop_regexp| /#{prop_regexp}/.match(prop) }
end
https?() click to toggle source
# File lib/redirus/worker/add_proxy.rb, line 56
def https?
  type.to_s == 'https'
end
location_properties(props) click to toggle source
# File lib/redirus/worker/add_proxy.rb, line 35
def location_properties(props)
  props.inject([]) do |tab, prop|
    tab << prop if allowed? prop
    tab
  end if props
end
template() click to toggle source
# File lib/redirus/worker/add_proxy.rb, line 48
def template
  File.read(template_path)
end
template_path() click to toggle source
# File lib/redirus/worker/add_proxy.rb, line 52
def template_path
  https? ? config.https_template : config.http_template
end