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.
48
49
50
|
# File 'lib/carthage_cache/configuration.rb', line 48
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
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/carthage_cache/configuration.rb', line 69
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.
46
47
48
|
# File 'lib/carthage_cache/configuration.rb', line 46
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
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/carthage_cache/configuration.rb', line 29
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
23
24
25
26
27
|
# File 'lib/carthage_cache/configuration.rb', line 23
def self.parse(str)
config = YAML.load(str)
raise "Invalid configuration" unless valid?(config)
new(config)
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
18
19
20
21
|
# File 'lib/carthage_cache/configuration.rb', line 15
def self.valid?(config)
config[:bucket_name] &&
config.has_key?(:aws_s3_client_options) &&
config[:aws_s3_client_options][:region] &&
config[:aws_s3_client_options][:access_key_id] &&
config[:aws_s3_client_options][:secret_access_key]
end
|
Instance Method Details
#merge(c) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/carthage_cache/configuration.rb', line 60
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
82
83
84
85
86
87
88
|
# File 'lib/carthage_cache/configuration.rb', line 82
def respond_to?(method_sym, include_private = false)
if self.class.supported_keys.include?(method_sym)
true
else
super
end
end
|
#to_yaml ⇒ Object
52
53
54
|
# File 'lib/carthage_cache/configuration.rb', line 52
def to_yaml
hash_object.to_yaml
end
|
#valid? ⇒ Boolean
56
57
58
|
# File 'lib/carthage_cache/configuration.rb', line 56
def valid?
self.class.valid?(hash_object)
end
|