gitenv 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gitenv"
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["AlphaHydrae"]
@@ -31,14 +31,16 @@ Gem::Specification.new do |s|
31
31
  "bin/gitenv",
32
32
  "gitenv.gemspec",
33
33
  "lib/gitenv.rb",
34
- "lib/gitenv/actions.rb",
35
- "lib/gitenv/all_files.rb",
34
+ "lib/gitenv/action.rb",
36
35
  "lib/gitenv/config.rb",
37
36
  "lib/gitenv/context.rb",
38
37
  "lib/gitenv/controller.rb",
39
38
  "lib/gitenv/copy.rb",
40
- "lib/gitenv/dot_files.rb",
41
39
  "lib/gitenv/enumerator.rb",
40
+ "lib/gitenv/enumerator/all_files.rb",
41
+ "lib/gitenv/enumerator/dot_files.rb",
42
+ "lib/gitenv/enumerator/enumerator.rb",
43
+ "lib/gitenv/enumerator/one_file.rb",
42
44
  "lib/gitenv/symlink.rb",
43
45
  "lib/program.rb",
44
46
  "spec/helper.rb",
@@ -2,9 +2,9 @@
2
2
  require 'paint'
3
3
 
4
4
  module Gitenv
5
- VERSION = '0.0.3'
5
+ VERSION = '0.0.4'
6
6
  end
7
7
 
8
- [ :context, :config, :controller, :symlink, :copy, :enumerator, :all_files, :dot_files, :actions ].each do |lib|
8
+ [ :context, :config, :controller, :symlink, :copy, :enumerator, :action ].each do |lib|
9
9
  require File.join(File.dirname(__FILE__), 'gitenv', lib.to_s)
10
10
  end
@@ -0,0 +1,18 @@
1
+
2
+ module Gitenv
3
+
4
+ class Action
5
+ include Context
6
+
7
+ def initialize config, type, files
8
+ @type, @files = type, files
9
+ copy! config
10
+ end
11
+
12
+ def each &block
13
+ @files.each File.join(*[repository, from_path].compact) do |f|
14
+ block.call @type.new(self, f)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -10,7 +10,7 @@ module Gitenv
10
10
 
11
11
  def initialize home
12
12
  @home = home
13
- @actions = Actions.new
13
+ @actions = []
14
14
  end
15
15
 
16
16
  def repo path
@@ -18,16 +18,7 @@ module Gitenv
18
18
  end
19
19
 
20
20
  def symlink file
21
-
22
- scope = self
23
- current_actions = Actions.new
24
- enumerator(file).each do |f|
25
- current_actions << Symlink.new(scope, f).tap do |action|
26
- @actions << action
27
- end
28
- end
29
-
30
- current_actions
21
+ Action.new(self, Symlink, enumerator(file)).tap{ |a| @actions << a }
31
22
  end
32
23
 
33
24
  def all_files
@@ -42,11 +33,11 @@ module Gitenv
42
33
 
43
34
  def enumerator file
44
35
  if file == :all_files
45
- AllFiles.new File.join(*[@repository, from_path].compact)
36
+ AllFiles.new
46
37
  elsif file == :dot_files
47
- DotFiles.new File.join(*[@repository, from_path].compact)
38
+ DotFiles.new
48
39
  else
49
- [ file ]
40
+ OneFile.new file
50
41
  end
51
42
  end
52
43
  end
@@ -2,45 +2,38 @@
2
2
  module Gitenv
3
3
 
4
4
  module Context
5
+ attr_accessor :home, :repository
6
+ attr_accessor :from_paths, :to_paths
5
7
 
6
8
  def from path, &block
7
- (@from_path ||= []) << path
9
+ (@from_paths ||= []) << path
8
10
  if block
9
11
  instance_eval &block
10
- @from_path.pop
12
+ @from_paths.pop
11
13
  end
12
14
  end
13
15
 
14
16
  def from_path
15
- @from_path ? File.join(*@from_path) : nil
16
- end
17
-
18
- def from_paths
19
- @from_path || []
20
- end
21
-
22
- def from_paths= paths
23
- @from_path = paths
17
+ @from_paths ? File.join(*@from_paths) : nil
24
18
  end
25
19
 
26
20
  def to path, &block
27
- (@to_path ||= []) << path
21
+ (@to_paths ||= []) << path
28
22
  if block
29
23
  instance_eval &block
30
- @to_path.pop
24
+ @to_paths.pop
31
25
  end
32
26
  end
33
27
 
34
28
  def to_path
35
- @to_path ? File.join(*@to_path) : nil
36
- end
37
-
38
- def to_paths
39
- @to_path || []
29
+ @to_paths ? File.join(*@to_paths) : nil
40
30
  end
41
31
 
42
- def to_paths= paths
43
- @to_path = paths
32
+ def copy! source
33
+ self.from_paths = source.from_paths ? source.from_paths.dup : []
34
+ self.to_paths = source.to_paths ? source.to_paths.dup : []
35
+ self.repository = source.repository
36
+ self.home = source.home
44
37
  end
45
38
  end
46
39
  end
@@ -14,9 +14,13 @@ module Gitenv
14
14
 
15
15
  def run
16
16
  load_config_file!
17
- @config.actions.each &:build!
18
- @config.actions.each &:update! if @action == :update
19
- @config.actions.each{ |a| puts a }
17
+ @config.actions.each do |a|
18
+ a.each do |impl|
19
+ impl.build!
20
+ impl.update! if @action == :update
21
+ puts impl
22
+ end
23
+ end
20
24
  end
21
25
 
22
26
  private
@@ -6,8 +6,7 @@ module Gitenv
6
6
 
7
7
  def initialize config, file
8
8
  @config, @file = config, file
9
- self.from_paths = config.from_paths.dup
10
- self.to_paths = config.to_paths.dup
9
+ copy! config
11
10
  end
12
11
  end
13
12
  end
@@ -1,20 +1,3 @@
1
-
2
- module Gitenv
3
-
4
- class FileEnumerator
5
-
6
- def initialize path
7
- @path = path
8
- end
9
-
10
- def files
11
- raise '#files not implemented'
12
- end
13
-
14
- def each &block
15
- files.each do |f|
16
- block.call f
17
- end
18
- end
19
- end
1
+ [ :enumerator, :all_files, :dot_files, :one_file ].each do |lib|
2
+ require File.join(File.dirname(__FILE__), 'enumerator', lib.to_s)
20
3
  end
@@ -0,0 +1,10 @@
1
+
2
+ module Gitenv
3
+
4
+ class AllFiles < FileEnumerator
5
+
6
+ def files path
7
+ Dir.entries(path).select{ |f| File.file? File.join(path, f) }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module Gitenv
3
+
4
+ class DotFiles < AllFiles
5
+
6
+ def files path
7
+ super(path).select{ |f| f.match /^\.[^\.]/ }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module Gitenv
3
+
4
+ class FileEnumerator
5
+
6
+ def files path
7
+ raise '#files not implemented'
8
+ end
9
+
10
+ def each path, &block
11
+ files(path).each{ |f| block.call f }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module Gitenv
3
+
4
+ class OneFile < FileEnumerator
5
+
6
+ def initialize file
7
+ @file = file
8
+ end
9
+
10
+ def files path
11
+ [ @file ]
12
+ end
13
+ end
14
+ end
@@ -7,8 +7,7 @@ module Gitenv
7
7
 
8
8
  def initialize config, file
9
9
  @config, @file = config, file
10
- self.from_paths = config.from_paths.dup
11
- self.to_paths = config.to_paths.dup
10
+ copy! config
12
11
  end
13
12
 
14
13
  def build!
@@ -17,7 +17,8 @@ command :update do |c|
17
17
  end
18
18
  end
19
19
 
20
- global_option '-c', '--config FILE', 'Use a custom configuration file (defaults to ~/.gitenv.rb)'
20
+ global_option '-r', '--repo PATH', 'Specify the path to the environment repository'
21
+ global_option '-c', '--config PATH', 'Use a custom configuration file (defaults to ~/.gitenv.rb)'
21
22
 
22
23
  default_command :info
23
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -193,14 +193,16 @@ files:
193
193
  - bin/gitenv
194
194
  - gitenv.gemspec
195
195
  - lib/gitenv.rb
196
- - lib/gitenv/actions.rb
197
- - lib/gitenv/all_files.rb
196
+ - lib/gitenv/action.rb
198
197
  - lib/gitenv/config.rb
199
198
  - lib/gitenv/context.rb
200
199
  - lib/gitenv/controller.rb
201
200
  - lib/gitenv/copy.rb
202
- - lib/gitenv/dot_files.rb
203
201
  - lib/gitenv/enumerator.rb
202
+ - lib/gitenv/enumerator/all_files.rb
203
+ - lib/gitenv/enumerator/dot_files.rb
204
+ - lib/gitenv/enumerator/enumerator.rb
205
+ - lib/gitenv/enumerator/one_file.rb
204
206
  - lib/gitenv/symlink.rb
205
207
  - lib/program.rb
206
208
  - spec/helper.rb
@@ -1,28 +0,0 @@
1
-
2
- module Gitenv
3
-
4
- class Actions
5
-
6
- def initialize
7
- @actions = []
8
- end
9
-
10
- def each &block
11
- @actions.each &block
12
- end
13
-
14
- def from path
15
- @actions.each{ |a| a.from path }
16
- @actions
17
- end
18
-
19
- def to path
20
- @actions.each{ |a| a.to path }
21
- @actions
22
- end
23
-
24
- def << action
25
- @actions << action
26
- end
27
- end
28
- end
@@ -1,10 +0,0 @@
1
-
2
- module Gitenv
3
-
4
- class AllFiles < FileEnumerator
5
-
6
- def files
7
- Dir.entries(@path).select{ |f| File.file? File.join(@path, f) }
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
-
2
- module Gitenv
3
-
4
- class DotFiles < AllFiles
5
-
6
- def files
7
- super.select{ |f| f.match /^\.[^\.]/ }
8
- end
9
- end
10
- end