Class: CarthageCache::Configuration

Inherits:
Object
  • Object
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.



54
55
56
# File 'lib/carthage_cache/configuration.rb', line 54

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



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/carthage_cache/configuration.rb', line 79

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_objectObject (readonly)

Returns the value of attribute hash_object.



52
53
54
# File 'lib/carthage_cache/configuration.rb', line 52

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

.defaultObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/carthage_cache/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']
    },
    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

Returns:

  • (Boolean)


19
20
21
# File 'lib/carthage_cache/configuration.rb', line 19

def self.read_only?(config)
  ConfigurationValidator.new(config).read_only?
end

.supported_keysObject



7
8
9
# File 'lib/carthage_cache/configuration.rb', line 7

def self.supported_keys
  @supported_keys ||= []
end

.valid?(config) ⇒ Boolean

Returns:

  • (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



70
71
72
73
74
75
76
77
# File 'lib/carthage_cache/configuration.rb', line 70

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

Returns:

  • (Boolean)


66
67
68
# File 'lib/carthage_cache/configuration.rb', line 66

def read_only?
  self.class.read_only?(self)
end

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
97
98
# File 'lib/carthage_cache/configuration.rb', line 92

def respond_to?(method_sym, include_private = false)
  if self.class.supported_keys.include?(method_sym)
    true
  else
    super
  end
end

#to_yamlObject



58
59
60
# File 'lib/carthage_cache/configuration.rb', line 58

def to_yaml
  hash_object.to_yaml
end

#valid?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/carthage_cache/configuration.rb', line 62

def valid?
  self.class.valid?(self)
end