Class: CarthageCache::Configuration
- Inherits:
-
Object
- Object
- CarthageCache::Configuration
show all
- Defined in:
- lib/carthage_cache/configuration.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash_object = {}) ⇒ Configuration
Returns a new instance of Configuration.
42
43
44
|
# File 'lib/carthage_cache/configuration.rb', line 42
def initialize(hash_object = {})
@hash_object = hash_object
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/carthage_cache/configuration.rb', line 63
def method_missing(method_sym, *arguments, &block)
method_name = method_sym.to_s
key = method_name.chomp("=")
return super if !self.class.supported_keys.include?(key.to_sym)
config, key = extract_config_and_key(key)
if method_name.end_with?("=")
config[key] = arguments.first
else
config[key]
end
end
|
Instance Attribute Details
#hash_object ⇒ Object
Returns the value of attribute hash_object.
40
41
42
|
# File 'lib/carthage_cache/configuration.rb', line 40
def hash_object
@hash_object
end
|
Class Method Details
.config_key(name) ⇒ Object
11
12
13
|
# File 'lib/carthage_cache/configuration.rb', line 11
def self.config_key(name)
supported_keys << name
end
|
.default ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/carthage_cache/configuration.rb', line 23
def self.default
@default ||= Configuration.new({
aws_s3_client_options: {
region: ENV['AWS_REGION'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
},
tmpdir: Dir.tmpdir
})
end
|
.parse(str) ⇒ Object
19
20
21
|
# File 'lib/carthage_cache/configuration.rb', line 19
def self.parse(str)
new(YAML.load(str))
end
|
.supported_keys ⇒ Object
7
8
9
|
# File 'lib/carthage_cache/configuration.rb', line 7
def self.supported_keys
@supported_keys ||= []
end
|
.valid?(config) ⇒ Boolean
15
16
17
|
# File 'lib/carthage_cache/configuration.rb', line 15
def self.valid?(config)
ConfigurationValidator.new(config).valid?
end
|
Instance Method Details
#merge(c) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/carthage_cache/configuration.rb', line 54
def merge(c)
if c.is_a?(Hash)
@hash_object = hash_object.merge(c)
else
@hash_object = hash_object.merge(c.hash_object)
end
self
end
|
#respond_to?(method_sym, include_private = false) ⇒ Boolean
76
77
78
79
80
81
82
|
# File 'lib/carthage_cache/configuration.rb', line 76
def respond_to?(method_sym, include_private = false)
if self.class.supported_keys.include?(method_sym)
true
else
super
end
end
|
#to_yaml ⇒ Object
46
47
48
|
# File 'lib/carthage_cache/configuration.rb', line 46
def to_yaml
hash_object.to_yaml
end
|
#valid? ⇒ Boolean
50
51
52
|
# File 'lib/carthage_cache/configuration.rb', line 50
def valid?
self.class.valid?(self)
end
|