rigit 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: 1b403c3545bfac4a469a6cd7cb1f5c7c11330ecc1bb31598a2975593d476f3f2
4
- data.tar.gz: 8f17237e2151a52b6d3b02934af55cf0d4ecff8dec8426a15092fd333c08986b
3
+ metadata.gz: 61bc7c4f474a82ed1c5a4c74696972482fbf5c583f0784cc842efeb6d74ffa63
4
+ data.tar.gz: ac7e0abb56fc7877c35ca670264e2a0aebc63a87b5e055d5e79f17ae4738d8eb
5
5
  SHA512:
6
- metadata.gz: e2ad0683933134b71cbf08b240b42870df0a47ad9481bab90851e20b2aaa3017e074822d8fc6c3821b3a41a3346ea8dfe8a7a5fbc5ae554231205671053492d9
7
- data.tar.gz: d1289c4489be8169b9f13d9c63206af7361f3b2aeab78a2d8bc1d434b8520c68775ed08e2e5bd18d9e920fa44948def09f8a1ac018572d02554e1c7c5e0eb845
6
+ metadata.gz: 6ae8b817dbdddfcfd36fad2b0b5a8ba7f9ba58e5a5cbc0cce261bde1645e01e83b1066c97c468ed3865718740bf0e8cc4c5aedd4a5992605a3434f46dfd55904
7
+ data.tar.gz: f0622b36f6c9d8d5d75a4a4b4c67d1717f265ab8775dba8ff1e32b25e7b15d32b7b93e9294c682796bb979414f1fd4f1412c984a04305864733b5d07fe6d3ed9
data/README.md CHANGED
@@ -214,7 +214,7 @@ params:
214
214
  spec:
215
215
  prompt: Include RSpec files?
216
216
  type: yesno
217
- default: y
217
+ default: yes
218
218
 
219
219
  console:
220
220
  prompt: "Select console:"
@@ -254,7 +254,7 @@ the below specifications:
254
254
  |-----------|----------------------------------------------------------|
255
255
  | `prompt` | The text to display when asking for user input |
256
256
  | `type` | The variable tyoe. Can be `yesno`, `text` or `select` |
257
- | `default` | The default value. When using `yesno`, use `y` and `n` |
257
+ | `default` | The default value. When using `yesno`, use `yes` or `no` |
258
258
  | `list` | An array of allowed options (only used in `select` type) |
259
259
 
260
260
  ---
@@ -11,6 +11,7 @@ module Rigit::Commands
11
11
  # Internal class to handle scaffolding for the {CommandLine} class.
12
12
  class BuildHandler
13
13
  attr_reader :args, :rig_name, :target_dir, :force
14
+ attr_accessor :overwrite_all, :skip_all
14
15
 
15
16
  include Colsole
16
17
 
@@ -26,18 +27,60 @@ module Rigit::Commands
26
27
  say config.intro if config.has_key? :intro
27
28
  verify_dirs
28
29
  arguments = prompt.get_input params
29
- rig.scaffold arguments:arguments, target_dir: target_dir do |file|
30
- if File.exist? file and !force
31
- tty_prompt.yes? "Overwrite #{file}?", default: false
32
- else
33
- true
34
- end
35
- end
30
+
31
+ scaffold arguments
32
+
36
33
  say config.has_key?(:outro) ? config.outro : "Done"
37
34
  end
38
35
 
39
36
  private
40
37
 
38
+ # Call Rig#scaffold while checking each file to see if it should be
39
+ # overwritten or not.
40
+ def scaffold(arguments)
41
+ rig.scaffold arguments: arguments, target_dir: target_dir do |file|
42
+ overwrite_file? file
43
+ end
44
+ end
45
+
46
+ # Check various scenarios to decide if the file should be overwritten
47
+ # or not. These are the scenarios covered by this method:
48
+ # 1. The user provided +--focce+ in the command line
49
+ # 2. The user answered "overwrite all" or "skip all" when he asked
50
+ # about the first conflicting file.
51
+ # 3. In cases where an additive dir contains a file that was originally
52
+ # new, approved or rejected - we use this existing knowledge (which
53
+ # is stored in +response_log+.
54
+ def overwrite_file?(file)
55
+ return response_log[file] if response_log.has_key? file
56
+
57
+ response_log[file] = true
58
+
59
+ unless overwrite_all or force
60
+ if skip_all
61
+ response_log[file] = false
62
+ elsif File.exist? file
63
+ response_log[file] = prompt_user_to_overwrite file
64
+ end
65
+ end
66
+
67
+ response_log[file]
68
+ end
69
+
70
+ def prompt_user_to_overwrite(file)
71
+ say "File !txtgrn!#{file}!txtrst! already exists."
72
+ tty_prompt.expand "Overwrite?" do |menu|
73
+ menu.choice key: 'y', name: 'overwrite', value: true
74
+ menu.choice key: 'n', name: 'skip', value: false
75
+ menu.choice key: 'a', name: 'overwrite all' do @overwrite_all = true; true end
76
+ menu.choice key: 's', name: 'skip all' do @skip_all = true; false end
77
+ end
78
+ end
79
+
80
+ def response_log
81
+ @response_log ||= {}
82
+ end
83
+
41
84
  def rig
42
85
  @rig ||= Rigit::Rig.new rig_name
43
86
  end
data/lib/rigit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rigit
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rigit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-01 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: super_docopt