carthage_cache 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 680503dd25d688ef0de26e7ad3e95365fdedd443
4
- data.tar.gz: 67f39166f2b86ae62d5d269802858b97a74a96cf
3
+ metadata.gz: 651775418076478a9fcb6ee5ba6f309b30a4a69a
4
+ data.tar.gz: 873fd418cf0782056954992dfdf7820a8c48f86d
5
5
  SHA512:
6
- metadata.gz: 3a9e552b4de67020ca75fec23e3be966a846c914b65602c7f4e9cd692bd2c344abb09dc75534419085966cf594393068d52176d2b022b8d779c0c253bb4f8884
7
- data.tar.gz: e904e08651ae39d53897495b030b23798998d4ec9ba6920f7c1671adc3e045aa3bc29a10cbafb52abb1a56aeba39f3514b1c78307f14cef1cd66eb9a34ea9a68
6
+ metadata.gz: 3b22d9d6a9281e1b568bba3daad57bbbe4b0b04c0e8437b08580c7b880d76acab6f2ff3cd40659f11a483992fad8d642a9742f5d7bc67d7c1f6dc83372f44518
7
+ data.tar.gz: 66a2de4ef7c86a3abdb0139342aea9666895969b089483ae7ae06b8f549a65e82ee96cef9639899854ee7adcfe6928979001e09e2e26662e0c83dfd0d2eead45
@@ -65,13 +65,8 @@ command :config do |c|
65
65
  c.description = "Generates a '#{CarthageCache::Configurator::CONFIG_FILE_NAME}' config file."
66
66
  c.action do |args, options|
67
67
  configurator = CarthageCache::Configurator.new(args.first || ".")
68
- config = {}
69
- config[:bucket_name] = ask "What is the Amazon S3 bucket name? [#{CarthageCache::Repository::DEFAULT_BUCKET_NAME}]"
70
- config[:aws_s3_client_options] = {}
71
- config[:aws_s3_client_options][:region] = ask "What is the Amazon S3 region?"
72
- config[:aws_s3_client_options][:access_key_id] = password "What is the AWS access key?"
73
- config[:aws_s3_client_options][:secret_access_key] = password " What is the AWS secret access key?"
74
- config.delete_if { |k,v| k == :bucket_name && v == "" }
68
+ wizard = CarthageCache::ConfiguratorWizard.new(method(:ask), method(:password))
69
+ config = wizard.start
75
70
  configurator.save_config(config)
76
71
  end
77
72
  end
@@ -7,7 +7,9 @@ require "carthage_cache/carthage_resolved_file"
7
7
  require "carthage_cache/project"
8
8
  require "carthage_cache/repository"
9
9
  require "carthage_cache/terminal"
10
+ require "carthage_cache/configuration"
10
11
  require "carthage_cache/configurator"
12
+ require "carthage_cache/configurator_wizard"
11
13
 
12
14
  module CarthageCache
13
15
 
@@ -19,13 +21,13 @@ module CarthageCache
19
21
  attr_reader :archiver
20
22
  attr_reader :repository
21
23
  attr_reader :project
22
- attr_reader :configurator
24
+ attr_reader :config
23
25
 
24
26
  def initialize(project_path, verbose, config)
25
27
  @terminal = Terminal.new(verbose)
26
28
  @archiver = Archiver.new
27
- @configurator = Configurator.new(project_path, config)
28
- @repository = Repository.new(configurator.config[:bucket_name], configurator.config[:aws_s3_client_options])
29
+ @config = Configurator.new(project_path, config).config
30
+ @repository = Repository.new(@config.bucket_name, @config.hash_object[:aws_s3_client_options])
29
31
  @project = Project.new(project_path, CACHE_DIR_NAME, terminal)
30
32
  end
31
33
 
@@ -8,9 +8,9 @@ module CarthageCache
8
8
  end
9
9
 
10
10
  def unarchive(archive_path, destination_path)
11
- `unzip #{archive_path} -d #{destination_path} > /dev/null`
11
+ `unzip -o #{archive_path} -d #{destination_path} > /dev/null`
12
12
  end
13
13
 
14
14
  end
15
-
15
+
16
16
  end
@@ -0,0 +1,100 @@
1
+ require "yaml"
2
+
3
+ module CarthageCache
4
+
5
+ class Configuration
6
+
7
+ def self.supported_keys
8
+ @supported_keys ||= []
9
+ end
10
+
11
+ def self.config_key(name)
12
+ supported_keys << name
13
+ end
14
+
15
+ def self.valid?(config)
16
+ config[:bucket_name] &&
17
+ config.has_key?(:aws_s3_client_options) &&
18
+ config[:aws_s3_client_options][:region] &&
19
+ config[:aws_s3_client_options][:access_key_id] &&
20
+ config[:aws_s3_client_options][:secret_access_key]
21
+ end
22
+
23
+ def self.parse(str)
24
+ config = YAML.load(str)
25
+ raise "Invalid configuration" unless valid?(config)
26
+ new(config)
27
+ end
28
+
29
+ def self.default
30
+ @default ||= Configuration.new({
31
+ aws_s3_client_options: {
32
+ region: ENV['AWS_REGION'],
33
+ access_key_id: ENV['AWS_ACCESS_KEY_ID'],
34
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
35
+ }
36
+ })
37
+ end
38
+
39
+ config_key :bucket_name
40
+ config_key :aws_region
41
+ config_key :aws_access_key_id
42
+ config_key :aws_secret_access_key
43
+
44
+ attr_reader :hash_object
45
+
46
+ def initialize(hash_object = {})
47
+ @hash_object = hash_object
48
+ end
49
+
50
+ def to_yaml
51
+ hash_object.to_yaml
52
+ end
53
+
54
+ def valid?
55
+ self.class.valid?(hash_object)
56
+ end
57
+
58
+ def merge(c)
59
+ if c.is_a?(Hash)
60
+ @hash_object = hash_object.merge(c)
61
+ else
62
+ @hash_object = hash_object.merge(c.hash_object)
63
+ end
64
+ self
65
+ end
66
+
67
+ def method_missing(method_sym, *arguments, &block)
68
+ method_name = method_sym.to_s
69
+ key = method_name.chomp("=")
70
+ return super if !self.class.supported_keys.include?(key.to_sym)
71
+ config, key = extract_config_and_key(key)
72
+
73
+ if method_name.end_with?("=")
74
+ config[key] = arguments.first
75
+ else
76
+ config[key]
77
+ end
78
+ end
79
+
80
+ def respond_to?(method_sym, include_private = false)
81
+ if self.class.supported_keys.include?(method_sym)
82
+ true
83
+ else
84
+ super
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def extract_config_and_key(method_name)
91
+ if method_name =~ /^aws_(.*)$/
92
+ [hash_object[:aws_s3_client_options] ||= {}, $1.to_sym]
93
+ else
94
+ [hash_object, method_name.to_sym]
95
+ end
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -11,7 +11,7 @@ module CarthageCache
11
11
 
12
12
  def initialize(project_path, base_config = {})
13
13
  @config_file_path = File.join(project_path, CONFIG_FILE_NAME)
14
- @base_config = default_configuration.merge(base_config)
14
+ @base_config = merge_config(base_config)
15
15
  end
16
16
 
17
17
  def config
@@ -19,9 +19,8 @@ module CarthageCache
19
19
  end
20
20
 
21
21
  def save_config(config)
22
- if valid?(config)
23
- File.open(config_file_path, 'w') { |f| f.write config.to_yaml }
24
- end
22
+ raise "Invalid configuration" unless config.valid?
23
+ File.open(config_file_path, 'w') { |f| f.write config.to_yaml }
25
24
  end
26
25
 
27
26
  private
@@ -32,35 +31,30 @@ module CarthageCache
32
31
 
33
32
  def load_config
34
33
  if config_file_exist?
35
- config = YAML.load(File.read(config_file_path))
36
- raise "Invalid config file" unless valid?(config)
34
+ config = Configuration.parse(File.read(config_file_path))
37
35
  config.merge(base_config)
38
36
  else
39
37
  base_config
40
38
  end
41
39
  end
42
40
 
43
- def valid?(config)
44
- config.has_key?(:aws_s3_client_options) &&
45
- config[:aws_s3_client_options][:region] &&
46
- config[:aws_s3_client_options][:access_key_id] &&
47
- config[:aws_s3_client_options][:secret_access_key]
48
- end
49
-
50
- def deep_symbolize_keys(object)
51
- return object.inject({}) { |memo,(k,v)| memo[k.to_sym] = deep_symbolize_keys(v); memo } if object.is_a? Hash
52
- return object.inject([]) { |memo,v | memo << deep_symbolize_keys(v); memo } if object.is_a? Array
53
- return object
41
+ def remove_nil_keys(hash)
42
+ hash.inject({}) do |new_hash, (k,v)|
43
+ unless v.nil? || (v.respond_to?(:empty?) && v.empty?)
44
+ if v.class == Hash
45
+ cleaned_hashed = remove_nil_keys(v)
46
+ new_hash[k] = cleaned_hashed unless cleaned_hashed.empty?
47
+ else
48
+ new_hash[k] = v
49
+ end
50
+ end
51
+ new_hash
52
+ end
54
53
  end
55
54
 
56
- def default_configuration
57
- config = {
58
- aws_s3_client_options: {}
59
- }
60
- config[:aws_s3_client_options][:region] = ENV['AWS_REGION'] if ENV['AWS_REGION']
61
- config[:aws_s3_client_options][:access_key_id] = ENV['AWS_ACCESS_KEY_ID'] if ENV['AWS_ACCESS_KEY_ID']
62
- config[:aws_s3_client_options][:secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY'] if ENV['AWS_SECRET_ACCESS_KEY']
63
- config.delete_if { |k, v| k == :aws_s3_client_options && v.empty? }
55
+ def merge_config(config)
56
+ new_config = Configuration.default.hash_object.merge(config)
57
+ Configuration.new(remove_nil_keys(new_config))
64
58
  end
65
59
 
66
60
  end
@@ -0,0 +1,37 @@
1
+ module CarthageCache
2
+
3
+ class ConfiguratorWizard
4
+
5
+ def initialize(ask_proc, password_proc)
6
+ @ask_proc = ask_proc
7
+ @password_proc = password_proc
8
+ end
9
+
10
+ def start
11
+ config = Configuration.new
12
+ config.bucket_name = ask("What is the Amazon S3 bucket name?", ENV["CARTHAGE_CACHE_DEFAULT_BUCKET_NAME"])
13
+ config.aws_region = ask("What is the Amazon S3 region?")
14
+ config.aws_access_key_id = password("What is the AWS access key?")
15
+ config.aws_secret_access_key = password(" What is the AWS secret access key?")
16
+ config
17
+ end
18
+
19
+ private
20
+
21
+ def ask(message, default_value = nil)
22
+ message = "#{message} [#{default_value}]" if default_value
23
+ answer = @ask_proc.call(message)
24
+ if answer.empty?
25
+ default_value
26
+ else
27
+ answer
28
+ end
29
+ end
30
+
31
+ def password(message)
32
+ @password_proc.call(message)
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -4,14 +4,12 @@ module CarthageCache
4
4
 
5
5
  class Repository
6
6
 
7
- DEFAULT_BUCKET_NAME = "carthage-cache"
8
-
9
7
  attr_reader :client
10
8
  attr_reader :bucket_name
11
9
 
12
10
  def initialize(bucket_name, client_options = {})
13
11
  @client = ::Aws::S3::Client.new(client_options)
14
- @bucket_name = bucket_name || DEFAULT_BUCKET_NAME
12
+ @bucket_name = bucket_name
15
13
  end
16
14
 
17
15
  def archive_exist?(archive_filename)
@@ -1,3 +1,3 @@
1
1
  module CarthageCache
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carthage_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guido Marucci Blas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-16 00:00:00.000000000 Z
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -123,7 +123,9 @@ files:
123
123
  - lib/carthage_cache/archive_installer.rb
124
124
  - lib/carthage_cache/archiver.rb
125
125
  - lib/carthage_cache/carthage_resolved_file.rb
126
+ - lib/carthage_cache/configuration.rb
126
127
  - lib/carthage_cache/configurator.rb
128
+ - lib/carthage_cache/configurator_wizard.rb
127
129
  - lib/carthage_cache/description.rb
128
130
  - lib/carthage_cache/project.rb
129
131
  - lib/carthage_cache/repository.rb