module RsyncConfig::Propertiable

Public Class Methods

included(base) click to toggle source
# File lib/rsync_config/propertiable.rb, line 5
def self.included base
  base.extend ClassMethods
end

Public Instance Methods

[](key, local_only = false) click to toggle source
# File lib/rsync_config/propertiable.rb, line 29
def [](key, local_only = false)
  key = sanitize_key(key)
  return nil if key.nil? 

  value = properties[key]
  return @parent_config[key] if !local_only && value.nil? && @parent_config.respond_to?(:[])

  value
end
[]=(key, value) click to toggle source
# File lib/rsync_config/propertiable.rb, line 47
def []=(key, value)
  key = sanitize_key(key)
  if value.nil?
    properties.delete key
  elsif value.is_a? ConfigEntry
    properties[key] = value
  else
    properties[key] = value.to_s
  end
end
properties_to_a() click to toggle source
# File lib/rsync_config/propertiable.rb, line 58
def properties_to_a
  properties.map { |key, value| "#{key} = #{value.to_s}" }
end
sanitize_key(key) click to toggle source
# File lib/rsync_config/propertiable.rb, line 39
def sanitize_key(key)
  key = key.to_s unless key.is_a? String
  key = key.strip.downcase
  return nil if key.length == 0
  return nil unless self.class.allowed_property? key
  key
end

Private Instance Methods

properties() click to toggle source
# File lib/rsync_config/propertiable.rb, line 64
def properties
  @properties ||= {}
end