Module: RsyncConfig::Propertiable
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #[](key, local_only = false) ⇒ Object
- #[]=(key, value) ⇒ Object
- #properties_to_a ⇒ Object
- #sanitize_key(key) ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'lib/rsync_config/propertiable.rb', line 5 def self.included base base.extend ClassMethods end |
Instance Method Details
#[](key, local_only = false) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# 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) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
58 59 60 |
# File 'lib/rsync_config/propertiable.rb', line 58 def properties_to_a properties.map { |key, value| "#{key} = #{value.to_s}" } end |
#sanitize_key(key) ⇒ Object
39 40 41 42 43 44 45 |
# 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 |