nib 1.4.2 → 1.5.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: fcfc968d8ee13c4739cb42a5afeddd81d5c45f1b
4
- data.tar.gz: 04db626c3a278a91cba59bfef4d2707875e326fd
3
+ metadata.gz: ebb0995546ce3958ff2a7421e5104fbe8c0ff2c4
4
+ data.tar.gz: 3dcef7fb5d744a7ce6c3cb7c21dfd5032b4c4b99
5
5
  SHA512:
6
- metadata.gz: 74ac8b08e4f48246cb6b6fb401225309cb2369175f83f1e3f2c394c0cb427880bebbe1f2e9392e7dff7e022482ad3700d5898e10227581ea0558907dbea27e50
7
- data.tar.gz: 26cceb3d695fb319555683fc00728714670c69cf3801f3d1bc9f4d7b7af3299b232a7367342451a1b8642a431a74884f68b189b18539a9743ed19913a74b2bde
6
+ metadata.gz: 9de1a488e77c341eb655c447ef65c95563a2bf63c24d6908e60a040e6dd295af78086be0d094b1dfbf1bde60633f981209f544a2bb9e768532e14caad58e593e
7
+ data.tar.gz: 3d335688fe79b27a8bc345a1aecfb07736fe0a7426556cb781ed3903f3cbf55891b2e3b4af5d1dd89a483546193af73fc6b74248ef43213582eb066fc1fe0d73
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.2
1
+ 1.5.0
data/lib/nib.rb CHANGED
@@ -8,6 +8,8 @@ require 'nib/options/parser'
8
8
 
9
9
  require 'nib/command'
10
10
  require 'nib/history'
11
+ require 'nib/history/compose'
12
+ require 'nib/history/config'
11
13
  require 'nib/check_for_update'
12
14
  require 'nib/unrecognized_help'
13
15
  require 'nib/code_climate'
@@ -24,11 +26,7 @@ module Nib
24
26
 
25
27
  module_function
26
28
 
27
- def load_config(command, file_name)
28
- File.read("#{GEM_ROOT}/config/commands/#{command}/#{file_name}")
29
- end
30
-
31
29
  def load_default_config(command, file_name)
32
- load_config(command, file_name)
30
+ File.read("#{GEM_ROOT}/config/commands/#{command}/#{file_name}")
33
31
  end
34
32
  end
@@ -1,5 +1,3 @@
1
- require 'tempfile'
2
-
3
1
  class Nib::CodeClimate
4
2
  include Nib::Command
5
3
 
@@ -12,24 +10,15 @@ class Nib::CodeClimate
12
10
 
13
11
  def script
14
12
  @script ||= <<-SCRIPT
15
- docker-compose \
16
- -f #{compose_file.path} \
17
- run \
13
+ docker run \
14
+ --interactive \
15
+ --tty \
18
16
  --rm \
19
- codeclimate \
20
- #{command}
17
+ --env CODECLIMATE_CODE="$PWD" \
18
+ --volume "$PWD":/code \
19
+ --volume /var/run/docker.sock:/var/run/docker.sock \
20
+ --volume /tmp/cc:/tmp/cc \
21
+ codeclimate/codeclimate #{command || 'help'}
21
22
  SCRIPT
22
23
  end
23
-
24
- private
25
-
26
- def config
27
- @config ||= Nib.load_config(:codeclimate, 'docker-compose.yml')
28
- end
29
-
30
- def compose_file
31
- @compose_file ||= Tempfile.open('compose') do |file|
32
- file.tap { |f| f.write(config) }
33
- end
34
- end
35
24
  end
@@ -26,6 +26,7 @@ module Nib::Command
26
26
  def script
27
27
  @script ||= <<-SCRIPT
28
28
  docker-compose \
29
+ #{alternate_compose_file} \
29
30
  run \
30
31
  --rm \
31
32
  #{options} \
@@ -33,4 +34,6 @@ module Nib::Command
33
34
  #{command}
34
35
  SCRIPT
35
36
  end
37
+
38
+ def alternate_compose_file; end
36
39
  end
@@ -1,10 +1,28 @@
1
- require 'fileutils'
2
-
3
1
  module Nib::History
2
+ PATH = '/usr/local/history'.freeze
3
+
4
+ def self.prepended(base)
5
+ base.instance_eval do
6
+ extend ClassMethods
7
+ end
8
+ end
9
+
10
+ module ClassMethods
11
+ def history_requires_command(value)
12
+ @history_requires_command = value
13
+ end
14
+
15
+ def history_requires_command?
16
+ @history_requires_command
17
+ end
18
+ end
19
+
4
20
  def command
21
+ return if self.class.history_requires_command? && @command.to_s.empty?
22
+
5
23
  <<-COMMAND
6
24
  /bin/sh -c \"
7
- export HISTFILE=./tmp/shell_history
25
+ export HISTFILE=#{PATH}/shell_history
8
26
  cp #{irbrc.container_path} /root/.irbrc 2>/dev/null
9
27
  cp #{pryrc.container_path} /root/.pryrc 2>/dev/null
10
28
  #{super}
@@ -12,51 +30,21 @@ module Nib::History
12
30
  COMMAND
13
31
  end
14
32
 
33
+ def alternate_compose_file
34
+ "-f #{Compose.new.path}"
35
+ end
36
+
15
37
  def irbrc
16
38
  @irbrc ||= Config.new(
17
39
  :irbrc,
18
- 'IRB.conf[:HISTORY_FILE] = "#{Dir.pwd}/tmp/irb_history"'
40
+ "IRB.conf[:HISTORY_FILE] = '#{PATH}/irb_history'"
19
41
  )
20
42
  end
21
43
 
22
44
  def pryrc
23
45
  @pryrc ||= Config.new(
24
46
  :pryrc,
25
- 'Pry.config.history.file = "#{Dir.pwd}/tmp/irb_history"'
47
+ "Pry.config.history.file = '#{PATH}/irb_history'"
26
48
  )
27
49
  end
28
-
29
- class Config
30
- attr_reader :type, :history_command, :host_path
31
-
32
- def initialize(type, history_command)
33
- @type = type
34
- @history_command = history_command
35
- @host_path = "#{ENV['HOME']}/.#{type}"
36
-
37
- FileUtils.mkdir_p './tmp'
38
- end
39
-
40
- def container_path
41
- config_file.path
42
- end
43
-
44
- private
45
-
46
- def config
47
- if File.exist?(host_path)
48
- File.read(host_path)
49
- else
50
- Nib.load_default_config(:shell, type)
51
- end
52
- end
53
-
54
- def config_file
55
- @config_file ||= File.open("./tmp/#{type}", 'w+') do |file|
56
- file.write(config)
57
- file.write(history_command + "\n")
58
- file
59
- end
60
- end
61
- end
62
50
  end
@@ -0,0 +1,95 @@
1
+ require 'tempfile'
2
+ require 'tmpdir'
3
+
4
+ class Nib::History::Compose
5
+ attr_reader :dir, :volume_name
6
+
7
+ def initialize
8
+ @volume_name = 'nib_history'
9
+ @dir = "#{Dir.tmpdir}/#{Dir.pwd.split('/').last}"
10
+
11
+ FileUtils.mkdir_p(dir)
12
+ end
13
+
14
+ def path
15
+ file.path
16
+ end
17
+
18
+ def config
19
+ original_config
20
+ .merge('services' => services_config)
21
+ .merge('volumes' => volumes_config)
22
+ end
23
+
24
+ private
25
+
26
+ def original_config
27
+ @original_config ||= YAML.safe_load(`docker-compose config`)
28
+ end
29
+
30
+ def file
31
+ @file ||= Tempfile.open('compose', dir) do |compose|
32
+ compose.write(config.to_yaml)
33
+ compose
34
+ end
35
+ end
36
+
37
+ def services_config
38
+ Services.new(volume_name, original_config['services']).config
39
+ end
40
+
41
+ def volumes_config
42
+ Volumes.new(volume_name, original_config['volumes']).config
43
+ end
44
+
45
+ class Services
46
+ attr_reader :original_config, :volume_name
47
+
48
+ def initialize(volume_name, original_config)
49
+ @original_config = original_config
50
+ @volume_name = volume_name
51
+ end
52
+
53
+ def config
54
+ original_config.each_with_object({}) do |(name, definition), extended|
55
+ extended[name] = Service.new(volume_name, definition).config
56
+ end
57
+ end
58
+ end
59
+
60
+ class Service
61
+ attr_reader :original_config, :volume_name
62
+
63
+ def initialize(volume_name, original_config)
64
+ @original_config = original_config
65
+ @volume_name = volume_name
66
+ end
67
+
68
+ def config
69
+ original_config.merge('volumes' => volumes_config << history_config)
70
+ end
71
+
72
+ private
73
+
74
+ def volumes_config
75
+ original_config['volumes'] || []
76
+ end
77
+
78
+ def history_config
79
+ "#{volume_name}:#{Nib::History::PATH}"
80
+ end
81
+ end
82
+
83
+ class Volumes
84
+ attr_reader :original_config, :volume_name
85
+
86
+ def initialize(volume_name, original_config = nil)
87
+ @original_config = original_config || {}
88
+ @volume_name = volume_name
89
+ end
90
+
91
+ def config
92
+ original_config.merge(volume_name => nil)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,35 @@
1
+ require 'fileutils'
2
+
3
+ class Nib::History::Config
4
+ attr_reader :type, :history_command, :host_path
5
+
6
+ def initialize(type, history_command)
7
+ @type = type
8
+ @history_command = history_command
9
+ @host_path = "#{ENV['HOME']}/.#{type}"
10
+
11
+ FileUtils.mkdir_p './tmp'
12
+ end
13
+
14
+ def container_path
15
+ config_file.path
16
+ end
17
+
18
+ private
19
+
20
+ def config
21
+ if File.exist?(host_path)
22
+ File.read(host_path)
23
+ else
24
+ Nib.load_default_config(:shell, type)
25
+ end
26
+ end
27
+
28
+ def config_file
29
+ @config_file ||= File.open("./tmp/#{type}", 'w+') do |file|
30
+ file.write(config)
31
+ file.write(history_command + "\n")
32
+ file
33
+ end
34
+ end
35
+ end
@@ -1,4 +1,6 @@
1
1
  class Nib::Run
2
2
  include Nib::Command
3
3
  prepend Nib::History
4
+
5
+ history_requires_command true
4
6
  end
@@ -2,19 +2,16 @@ class Nib::Shell
2
2
  include Nib::Command
3
3
  prepend Nib::History
4
4
 
5
- SCRIPT = <<-SH.freeze
6
- if hash bash 2>/dev/null ; then
7
- bash
8
- elif hash ash 2>/dev/null ; then
9
- ash
10
- else
11
- sh
12
- fi
13
- SH
14
-
15
5
  private
16
6
 
17
7
  def command
18
- SCRIPT
8
+ conditions = %i(zsh bash ash).map do |shell|
9
+ "elif hash #{shell} 2>/dev/null ; then #{shell};"
10
+ end
11
+
12
+ conditions # default conditions
13
+ .unshift('if [ -f bin/shell ]; then bin/shell;') # prepend bin/shell
14
+ .push('else sh; fi') # add else clause (`sh`)
15
+ .join("\n")
19
16
  end
20
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Allen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-22 00:00:00.000000000 Z
12
+ date: 2017-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
@@ -129,14 +129,14 @@ dependencies:
129
129
  requirements:
130
130
  - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: 1.0.5
132
+ version: 1.0.6
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: 1.0.5
139
+ version: 1.0.6
140
140
  description: |2
141
141
  nib is a docker-compose wrapper geared towards Ruby/Rails development.
142
142
  email:
@@ -149,7 +149,6 @@ files:
149
149
  - VERSION
150
150
  - bin/nib
151
151
  - config/commands.json
152
- - config/commands/codeclimate/docker-compose.yml
153
152
  - config/commands/shell/irbrc
154
153
  - config/commands/shell/pryrc
155
154
  - config/options.yml
@@ -162,6 +161,8 @@ files:
162
161
  - lib/nib/debug.rb
163
162
  - lib/nib/exec.rb
164
163
  - lib/nib/history.rb
164
+ - lib/nib/history/compose.rb
165
+ - lib/nib/history/config.rb
165
166
  - lib/nib/options.rb
166
167
  - lib/nib/options/augmenter.rb
167
168
  - lib/nib/options/parser.rb
@@ -1,12 +0,0 @@
1
- version: '2'
2
-
3
- services:
4
- codeclimate:
5
- image: codeclimate/codeclimate
6
- environment:
7
- - CODECLIMATE_CODE=$PWD
8
- volumes:
9
- - $PWD:/code
10
- - $PWD:$PWD
11
- - /var/run/docker.sock:/var/run/docker.sock
12
- - /tmp/cc:/tmp/cc