auto-gemsets 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,9 @@
1
1
  #Changelog
2
2
 
3
+ ## Version 0.1.7
4
+ - Fixed a bug where calling gemset with -v would error
5
+ - Set appropriate gem bin directories in PATH
6
+ - Namespace functions to avoid collisions
7
+
3
8
  ## Version 0.1.6
4
9
  - Fixed a bug where the gemset bin path was being duplicated in $PATH
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "auto-gemsets"
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dayton Nolan"]
12
- s.date = "2012-12-21"
12
+ s.date = "2012-12-22"
13
13
  s.description = "auto-gemsets creates a gemset named after the parent directory of every Gemfile you encounter. This let's you automatically scope your gems without using shims or creating gemsets. "
14
14
  s.email = "dnolan@gmail.com"
15
15
  s.executables = ["gemset"]
@@ -1,67 +1,123 @@
1
- function create_gemset_if_missing() {
2
- if [ ! -d "${GEMSET_ROOT}/${GEMSET}" ]; then
3
- mkdir -p "${GEMSET_ROOT}/${GEMSET}" && echo "${GEMSET} created. run gem install bundler"
1
+ ag_set_default_gemset() {
2
+ if [ -n "${DEFAULT_GEMSET}" ]; then
3
+ if [ ! "$GEM_PATH" == "${DEFAULT_GEMSET}" ]; then
4
+ DEFAULT=$( basename $DEFAULT_GEMSET )
5
+ fi
6
+
7
+ if [ -n "$GEMSET" ] && [ ! "$GEMSET" == "$DEFAULT" ]; then
8
+ ag_remove_path "${GEMSET_ROOT}/${GEMSET}/bin"
9
+ fi
10
+
11
+ DEFAULT_BIN_PATH="${DEFAULT_GEMSET}/bin"
12
+
13
+ export GEMSET="${DEFAULT}"
14
+ export GEM_HOME="$DEFAULT_GEMSET"
15
+ export GEMFILE="$DEFAULT_GEMSET"
16
+ export GEM_ROOT="$GEM_HOME"
17
+ export GEM_PATH="$GEM_HOME"
18
+
19
+ ag_add_path "$DEFAULT_BIN_PATH"
20
+ ag_using_gemset_via "*default"
21
+ fi
22
+ }
23
+
24
+ ag_using_gemset_via() {
25
+ echo "Now using $GEMSET gemset via $1"
26
+ }
27
+
28
+ ag_remove_path() {
29
+ NEW_PATH=""
30
+ IFS=':' read -a PATHS <<< "$PATH"
31
+ for p in "${PATHS[@]}"
32
+ do
33
+ if [ ! "$p" == "$1" ]; then
34
+ if [ -z "$NEW_PATH" ]; then
35
+ NEW_PATH="$p"
36
+ else
37
+ NEW_PATH="$NEW_PATH:$p"
38
+ fi
39
+ fi
40
+ done
41
+ export PATH="$NEW_PATH"
42
+ }
43
+
44
+ ag_add_path () {
45
+ if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then
46
+ if [ "$2" = "after" ] ; then
47
+ PATH=$PATH:$1
48
+ else
49
+ PATH=$1:$PATH
50
+ fi
51
+
52
+ export PATH
4
53
  fi
5
54
  }
6
55
 
7
- function auto_gemsets() {
56
+ auto_gemsets() {
8
57
  local dir="$PWD"
9
- local version_file
10
58
 
11
59
  until [[ -z "$dir" ]]; do
12
- gemfile="$dir/Gemfile"
13
- IFS='/' read -a gemfile_path_parts <<< "$gemfile"
14
- gemset="${gemfile_path_parts[${#gemfile_path_parts[@]}-2]}"
15
-
16
- if [[ "${GEM_PATH//:$DEFAULT_GEMSET}" == "${GEMSET_ROOT}/$gemset" ]]; then return
17
- elif [[ -f "$gemfile" ]]; then
18
- export GEM_HOME="${GEMSET_ROOT}/$gemset"
19
- export GEM_ROOT="${GEMSET_ROOT}/$gemset" # chruby specific
20
- export GEM_PATH="${GEM_HOME}:${DEFAULT_GEMSET}"
21
- echo "$PATH" | grep -q "${GEMSET_ROOT}/${gemset}/bin" || export PATH="$PATH:${GEMSET_ROOT}/${gemset}/bin"
22
- export GEMSET="${gemset}"
23
- export GEMFILE="${gemfile}"
24
- create_gemset_if_missing && list_gemset
25
- break
26
- elif [[ ! -f "$gemfile" ]]; then
27
- set_default_gemset
60
+ GEMFILE="$dir/Gemfile"
61
+
62
+ if [ -f "$GEMFILE" ]; then
63
+ ag_get_parent_dirname
64
+ if [ "$GEMSET" == "$PARENT_DIR" ]; then
65
+ break
66
+ else
67
+ ag_set_gemset "$PARENT_DIR"
68
+ break
69
+ fi
70
+ else
71
+ if [ ! "$GEMSET" == "$DEFAULT" ]; then
72
+ ag_set_default_gemset
73
+ fi
28
74
  fi
29
75
 
30
76
  dir="${dir%/*}"
31
77
  done
32
78
  }
33
79
 
34
- function set_default_gemset() {
35
- if [ ! -z "${DEFAULT_GEMSET}" ]; then
36
- if [ ! "$GEM_PATH" == "${DEFAULT_GEMSET}" ]; then
37
- export GEM_HOME="$DEFAULT_GEMSET"
38
- export GEM_ROOT="$DEFAULT_GEMSET"
39
- export GEM_PATH="$DEFAULT_GEMSET"
40
- export GEMSET="daytonn"
41
- export GEMFILE="*default"
80
+ ag_get_parent_dirname() {
81
+ IFS='/' read -a gemfile_path_parts <<< "$GEMFILE"
82
+ PARENT_DIR="${gemfile_path_parts[${#gemfile_path_parts[@]}-2]}"
83
+ }
42
84
 
43
- echo "$PATH" | grep -q "${DEFAULT_GEMSET}/bin" || export PATH="$PATH:${DEFAULT_GEMSET}/bin"
85
+ ag_set_gemset() {
86
+ NEW_GEMSET="$1"
87
+ NEW_GEMSET_PATH="${GEMSET_ROOT}/${1}"
88
+ NEW_GEMSET_BIN_PATH="${NEW_GEMSET_PATH}/bin"
89
+ ag_remove_path "$GEMSET_BIN_PATH"
90
+ ag_create_gemset_if_missing "$NEW_GEMSET"
91
+ export GEMSET="$NEW_GEMSET"
92
+ export GEM_HOME="$NEW_GEMSET_PATH"
93
+ export GEM_ROOT="$NEW_GEMSET_PATH"
94
+ export GEM_PATH="$NEW_GEMSET_PATH:$DEFAULT_GEMSET"
44
95
 
45
- if [ -z "$GEMSET_PRELOAD" ]; then
46
- list_gemset
47
- fi
48
- fi
49
- fi
96
+ ag_add_path "$DEFAULT_BIN_PATH"
97
+ ag_add_path "$NEW_GEMSET_BIN_PATH"
98
+
99
+ ag_using_gemset_via "$GEMFILE"
50
100
  }
51
101
 
52
- function list_gemset() {
53
- echo "Now using ${GEMSET} gemset via ${GEMFILE}"
102
+ ag_create_gemset_if_missing() {
103
+ if [ ! -d "${GEMSET_ROOT}/${1}" ]; then
104
+ mkdir -p "${GEMSET_ROOT}/${1}" && echo "${1} created. run gem install bundler"
105
+ fi
54
106
  }
55
107
 
108
+ # Create a GEMSET_ROOT if none is set
56
109
  if [ ! -n "$GEMSET_ROOT" ]; then
57
110
  export GEMSET_ROOT="${HOME}/.gemsets"
58
111
  fi
59
112
 
113
+ # If ZSH add precommand
60
114
  if [[ -n "$ZSH_VERSION" ]]; then
61
115
  precmd_functions+=("auto_gemsets")
62
116
  else
63
- if [[ -n "$PROMPT_COMMAND" ]]; then
64
- if [[ ! "$PROMPT_COMMAND" == *auto_gemsets* ]]; then
117
+ # If there's already a prompt command,
118
+ if [ -n "$PROMPT_COMMAND" ]; then
119
+ # check if it's already in the PROMPT
120
+ if [ ! "$PROMPT_COMMAND" == *auto_gemsets* ]; then
65
121
  PROMPT_COMMAND="$PROMPT_COMMAND; auto_gemsets"
66
122
  fi
67
123
  else
@@ -69,11 +125,5 @@ else
69
125
  fi
70
126
  fi
71
127
 
72
- function init() {
73
- # Set default on load
74
- GEMSET_PRELOAD="true"
75
- set_default_gemset
76
- unset GEMSET_PRELOAD
77
- }
78
-
79
- init
128
+ # Set default when sourced
129
+ ag_set_default_gemset
@@ -36,7 +36,13 @@ module AutoGemsets
36
36
  if @command
37
37
  self.send @command, *@args
38
38
  else
39
- options[:help] ? help : self.send(:current)
39
+ if options[:help]
40
+ help
41
+ elsif options[:version]
42
+ version
43
+ else
44
+ self.send(:current)
45
+ end
40
46
  end
41
47
  end
42
48
 
@@ -139,7 +145,6 @@ module AutoGemsets
139
145
  OptionParser.new do |opts|
140
146
  opts.on("-v", "--version", "Version info") do
141
147
  @options[:version] = true
142
- version
143
148
  end
144
149
 
145
150
  opts.on('-h', '--help', 'Display help') do
@@ -155,10 +160,7 @@ module AutoGemsets
155
160
  end
156
161
 
157
162
  def version
158
- version = File.read("#{AutoGemsets::base_directory}/VERSION")
159
- message = "auto-gemsets #{version}\n"
160
- message << "Copyright (c) #{Time.now.year} Dayton Nolan\n"
161
- @output.puts message
163
+ @output.puts "auto-gemsets #{AutoGemsets::VERSION}"
162
164
  end
163
165
 
164
166
  def gemset_path(gemset)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto-gemsets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-21 00:00:00.000000000 Z
12
+ date: 2012-12-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -149,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  segments:
151
151
  - 0
152
- hash: 3386426079743793721
152
+ hash: -185994835984614763
153
153
  required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  none: false
155
155
  requirements: