capistrano-lazy 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 025f5045fde58cb14efefc58c0e8bcec7550fcae
4
- data.tar.gz: 692f1445cb4a6929b6c628dd7364016bfda0ce2a
3
+ metadata.gz: 5aa1ca4b4796d75c753ec60a4ab7b4bdb959d3ec
4
+ data.tar.gz: ef98bf8f7ec2673777728a495f08a7861695a1ca
5
5
  SHA512:
6
- metadata.gz: 6b5540a2c1744904ed7fbb9b40c31f5c6e1458b339e071ccf934844449dc83dceaa344aae5edd3aabfdc86684ccb5bdc388dbc9617c540ec14f778628d56a023
7
- data.tar.gz: 3e33d8c0544b7e300c3f30119c574d00c4512b9981b6b0dc1a86455b9c4efcdc73a5a67d3c0ca39557072f688bf67dc7d23ebf84787d3b2e7f1fa468a9f2f4b2
6
+ metadata.gz: c08e3044250617bc82a3048f535bb01aa0b2453e98e5f8edd8eac7659751958017ecfdbc85616679ca6435ebc0294aa87ce6ce264058e088de0684f048e889e5
7
+ data.tar.gz: 757109f8c6edd3e55386e50d6052bd6c2009203f3179cd18f447e095ad0295e11c7213af87d3944f8b972980f83310aff337d251efc776fdf0d03188133b5be3
data/README.md CHANGED
@@ -18,6 +18,29 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ ### Bootstrapping YAML configuration files
22
+
23
+ This task is used together with the remote file task.
24
+ It will bootstrap remote YAML configuration files based on `.yml.example` templates.
25
+ It will parse the file asking for values, save and upload the file remote.
26
+
27
+ ```ruby
28
+ require 'capistrano/lazy/yaml_file_tasks'
29
+ ```
30
+
31
+ Loads the default task to bootstrap the `database.yml`.
32
+
33
+ To add more files to be managed, add those to the `linked_files` list and create a task based on this:
34
+
35
+ ```ruby
36
+ remote_file 'config/database.yml' => './config/database.yml', :roles => :db
37
+ file './config/database.yml' do |f|
38
+ yaml_file(f.name)
39
+ end
40
+ ```
41
+
42
+ To recreate the file. Just remove the local and remote files you want to be recreated.
43
+
21
44
  ### Rbenv and Ruby build tasks
22
45
 
23
46
  I added a couple of tasks to manage rbenv and ruby-build remote setup, update and rubies installation.
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Lazy
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -0,0 +1,4 @@
1
+ remote_file 'config/database.yml' => './config/database.yml', :roles => :db
2
+ file './config/database.yml' do |f|
3
+ yaml_file(f.name)
4
+ end
@@ -0,0 +1,5 @@
1
+ require 'capistrano/lazy/yaml_files'
2
+
3
+ include ::Capistrano::DSL::YamlFiles
4
+
5
+ load File.expand_path('../tasks/database_yml.rake', __FILE__)
@@ -0,0 +1,36 @@
1
+ require 'yaml'
2
+
3
+ module ::Capistrano::DSL::YamlFiles
4
+ # Its like `ask` but stateless
5
+ def ask_for_value(key, default)
6
+ question = ::Capistrano::Configuration::Question.new(self, key, default)
7
+ yield question
8
+ end
9
+
10
+ # Creates the file based on existing example YAML file
11
+ def yaml_file(file_path)
12
+ file_name = File.basename(file_path)
13
+ example_file = File.expand_path(file_name + '.example', 'config')
14
+
15
+ puts 'Creating file %s using %s' % [file_name, example_file]
16
+ puts '...'
17
+
18
+ reading_example(example_file) do |hash|
19
+ File.write(file_path, hash.to_yaml)
20
+ end
21
+ end
22
+
23
+ # Reads an example file and asks if its values need to be changed
24
+ def reading_example(yml_example_file)
25
+ yml_env = fetch(:stage).to_s
26
+ yml_hash = YAML.load_file(yml_example_file.to_s)
27
+ yml_hash[yml_env].each do |key, val|
28
+ unless val.is_a? Hash
29
+ ask_for_value(key, val) do |answer|
30
+ yml_hash[yml_env][key] = answer.call
31
+ end
32
+ end
33
+ end
34
+ yield yml_hash.slice(yml_env)
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-lazy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas SUȘCOV
@@ -66,6 +66,9 @@ files:
66
66
  - Rakefile
67
67
  - capistrano-lazy.gemspec
68
68
  - lib/capistrano/lazy.rb
69
+ - lib/capistrano/lazy/tasks/database_yml.rake
70
+ - lib/capistrano/lazy/yaml_file_tasks.rb
71
+ - lib/capistrano/lazy/yaml_files.rb
69
72
  - lib/capistrano/rbenv/lazy.rb
70
73
  - lib/capistrano/rbenv/tasks/lazy.rake
71
74
  homepage: https://github.com/stas/capistrano-lazy