Class: CarthageCacheRes::Configuration
- Inherits:
-
Object
- Object
- CarthageCacheRes::Configuration
- Defined in:
- lib/carthage_cache_res/configuration.rb
Instance Attribute Summary collapse
-
#hash_object ⇒ Object
readonly
Returns the value of attribute hash_object.
Class Method Summary collapse
- .config_key(name) ⇒ Object
- .default ⇒ Object
- .parse(str) ⇒ Object
- .read_only?(config) ⇒ Boolean
- .supported_keys ⇒ Object
- .valid?(config) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(hash_object = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #merge(c) ⇒ Object
- #method_missing(method_sym, *arguments, &block) ⇒ Object
- #read_only? ⇒ Boolean
- #respond_to?(method_sym, include_private = false) ⇒ Boolean
- #to_yaml ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(hash_object = {}) ⇒ Configuration
Returns a new instance of Configuration.
59 60 61 |
# File 'lib/carthage_cache_res/configuration.rb', line 59 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
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/carthage_cache_res/configuration.rb', line 89 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 (readonly)
Returns the value of attribute hash_object.
57 58 59 |
# File 'lib/carthage_cache_res/configuration.rb', line 57 def hash_object @hash_object end |
Class Method Details
.config_key(name) ⇒ Object
11 12 13 |
# File 'lib/carthage_cache_res/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 38 39 40 41 42 43 |
# File 'lib/carthage_cache_res/configuration.rb', line 27 def self.default @default ||= Configuration.new({ prune_on_publish: false, platforms: nil, prune_white_list: nil, 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'], session_token: ENV['AWS_SESSION_TOKEN'] }, tmpdir: File.join(Dir.home, 'Library', 'Caches'), archive_base_path: nil }) end |
.parse(str) ⇒ Object
23 24 25 |
# File 'lib/carthage_cache_res/configuration.rb', line 23 def self.parse(str) new(YAML.load(str)) end |
.read_only?(config) ⇒ Boolean
19 20 21 |
# File 'lib/carthage_cache_res/configuration.rb', line 19 def self.read_only?(config) ConfigurationValidator.new(config).read_only? end |
.supported_keys ⇒ Object
7 8 9 |
# File 'lib/carthage_cache_res/configuration.rb', line 7 def self.supported_keys @supported_keys ||= [] end |
.valid?(config) ⇒ Boolean
15 16 17 |
# File 'lib/carthage_cache_res/configuration.rb', line 15 def self.valid?(config) ConfigurationValidator.new(config).valid? end |
Instance Method Details
#merge(c) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/carthage_cache_res/configuration.rb', line 75 def merge(c) other_hash = nil if c.is_a?(Hash) other_hash = c else other_hash = c.hash_object end @hash_object = hash_object.merge(other_hash) do |key, oldval, newval| oldval.is_a?(Hash) ? oldval.merge(newval) : newval end self end |
#read_only? ⇒ Boolean
71 72 73 |
# File 'lib/carthage_cache_res/configuration.rb', line 71 def read_only? self.class.read_only?(self) end |
#respond_to?(method_sym, include_private = false) ⇒ Boolean
102 103 104 105 106 107 108 |
# File 'lib/carthage_cache_res/configuration.rb', line 102 def respond_to?(method_sym, include_private = false) if self.class.supported_keys.include?(method_sym) true else super end end |
#to_yaml ⇒ Object
63 64 65 |
# File 'lib/carthage_cache_res/configuration.rb', line 63 def to_yaml hash_object.to_yaml end |
#valid? ⇒ Boolean
67 68 69 |
# File 'lib/carthage_cache_res/configuration.rb', line 67 def valid? self.class.valid?(self) end |