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
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/carthage_cache/configuration.rb', line 73
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
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/carthage_cache/configuration.rb', line 27
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'],
profile: ENV['AWS_PROFILE']
},
tmpdir: File.join(Dir.home, 'Library', 'Caches')
})
end
|
.parse(str) ⇒ Object
23
24
25
|
# File 'lib/carthage_cache/configuration.rb', line 23
def self.parse(str)
new(YAML.load(str))
end
|
.read_only?(config) ⇒ Boolean
.supported_keys ⇒ Object
7
8
9
|
# File 'lib/carthage_cache/configuration.rb', line 7
def self.supported_keys
@supported_keys ||= []
end
|
.valid?(config) ⇒ Boolean
Instance Method Details
#merge(c) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/carthage_cache/configuration.rb', line 64
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
|
#read_only? ⇒ Boolean
60
61
62
|
# File 'lib/carthage_cache/configuration.rb', line 60
def read_only?
self.class.read_only?(self)
end
|
#respond_to?(method_sym, include_private = false) ⇒ Boolean
86
87
88
89
90
91
92
|
# File 'lib/carthage_cache/configuration.rb', line 86
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?(self)
end
|