treebis 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/NEWS.md +7 -0
  2. data/README +2 -2
  3. data/Rakefile +0 -1
  4. data/VERSION +1 -1
  5. data/lib/treebis.rb +24 -10
  6. data/test/test-for-doc.rb +1 -1
  7. metadata +6 -17
data/NEWS.md ADDED
@@ -0,0 +1,7 @@
1
+ # treebis news
2
+
3
+ ### 0.0.2 (2010-05-13)
4
+ * search for persistent dotfiles in more than one location (if PWD might be one of several locations)
5
+
6
+ ### 0.0.1 (2010-05-11)
7
+ * before there was news there was this
data/README CHANGED
@@ -12,7 +12,7 @@ minimal single-file rake-like task DSL for wrapping common filesystem tasks like
12
12
 
13
13
 
14
14
  ## description
15
- Treebis is a minimal, general scripting/task utility written in ruby that wraps common actions for moving, copying and altering filetrees. It is geared towards things like generators. It is comparable to a shell script that does a lot of mkdir, mv, cp commmands etc.
15
+ Treebis is a minimal, general scripting/task utility written in ruby that wraps common actions for moving, copying and altering filetrees. It is geared towards things like generators. It is comparable to a shell script that does a lot of mkdir, mv, cp commands etc.
16
16
 
17
17
 
18
18
  ## what it is:
@@ -42,7 +42,7 @@ Treebis is a minimal, general scripting/task utility written in ruby that wraps
42
42
  <span class='answer'>A</span>: because it rhymes with "Jeebus."
43
43
 
44
44
  ### Q: why did you make this?
45
- <span class='answer'>A</span>: by the third or fourth time i found myself re-writing this same kind of thing for different projects, or bleeding from its absence, i decided to abstract it. It's more readable than a bunch of FileUtils statements, it paves the way for possible future enhancements like atomicitiy and units of work; and wouldn't it be nice if every generator of every project used the same library?
45
+ <span class='answer'>A</span>: by the third or fourth time i found myself re-writing this same kind of thing for different projects, or bleeding from its absence, i decided to abstract it. It's more readable than a bunch of FileUtils statements, it paves the way for possible future enhancements like atomicicity (atomic-ness?) and units of work; and wouldn't it be nice if every generator of every project used the same library?
46
46
 
47
47
  ## requirements
48
48
  - ruby 1.8.7
data/Rakefile CHANGED
@@ -34,7 +34,6 @@ require 'nandoc'
34
34
  require 'nandoc/parse-readme'
35
35
 
36
36
  Jeweler::Tasks.new do |s|
37
- s.add_dependency 'json'
38
37
  s.authors = ['Chip Malice']
39
38
  s.description = NanDoc::ParseReadme.description('README')
40
39
  s.files = FileList['[A-Z]*', '{bin,doc,generators,lib,test}/**/*']
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/treebis.rb CHANGED
@@ -569,7 +569,6 @@ module Treebis
569
569
  @name = name
570
570
  @ui_stack = []
571
571
  end
572
- attr_reader :erb_values
573
572
  def erb_values hash
574
573
  @erb_values = hash
575
574
  self
@@ -833,8 +832,8 @@ end
833
832
  module Treebis
834
833
  module PersistentDotfile
835
834
  class << self
836
- def extend_to(tgt, dotfile_path, opts={})
837
- opts = {:file_utils=>FileUtils, :dotfile_path=>dotfile_path}.
835
+ def extend_to(tgt, dotfile_paths, opts={})
836
+ opts = {:file_utils=>FileUtils, :dotfile_paths=>dotfile_paths}.
838
837
  merge(opts)
839
838
  tgt.extend ClassMethods
840
839
  tgt.persistent_dotfile_init opts
@@ -846,15 +845,30 @@ module Treebis
846
845
  end
847
846
  DelegatedMethods = %w(tmpdir empty_tmpdir persistent_set persistent_get)
848
847
  module ClassMethods
849
- attr_accessor :dotfile_path, :file_utils
848
+ attr_accessor :dotfile_paths, :file_utils
850
849
 
851
850
  def persistent_dotfile_init opts
852
- @dotfile_path ||= opts[:dotfile_path]
851
+ dfp =
852
+ case opts[:dotfile_paths]
853
+ when Array; opts[:dotfile_paths]
854
+ when String; [opts[:dotfile_paths]]
855
+ else fail("dotfile_path(s) must be string or array, not "<<
856
+ " #{opts[:dofile_paths].inspect}")
857
+ end
858
+ @dotfile_paths = dfp
853
859
  @file_utils ||= opts[:file_utils]
854
860
  @persistent_struct ||= nil
855
861
  @tmpdir ||= nil
856
862
  end
857
863
 
864
+ def dotfile_path_first_that_exists
865
+ @dotfile_paths.detect{ |p| File.exist?(p) }
866
+ end
867
+
868
+ def dotfile_path_to_write_to
869
+ dotfile_path_first_that_exists || @dotfile_paths.first
870
+ end
871
+
858
872
  #
859
873
  # if it exists delete it. create it. file_utils must be defined
860
874
  # @return path to new empty directory
@@ -916,8 +930,8 @@ module Treebis
916
930
  @persistent_struct
917
931
  elsif @persistent_struct == false
918
932
  nil
919
- elsif File.exists? dotfile_path
920
- @persistent_struct = JSON.parse(File.read(dotfile_path))
933
+ elsif path = dotfile_path_first_that_exists
934
+ @persistent_struct = JSON.parse(File.read(path))
921
935
  else
922
936
  @persistent_struct = false
923
937
  end
@@ -926,7 +940,7 @@ module Treebis
926
940
  def persistent_set path, value
927
941
  struct = persistent_struct || (@persistent_struct = {})
928
942
  struct[path] = value
929
- File.open(dotfile_path, 'w+') do |fh|
943
+ File.open(dotfile_path_to_write_to, 'w+') do |fh|
930
944
  fh.write JSON.pretty_generate(struct)
931
945
  end
932
946
  nil
@@ -1429,7 +1443,7 @@ if [__FILE__, '/usr/bin/rcov'].include?($PROGRAM_NAME) # ick
1429
1443
  def test_copy_one_file_nothing_exist
1430
1444
  out_dir = tmpdir+'/out-dir'
1431
1445
  src_file = tmpdir+'/baz.txt'
1432
- per_file = self.class.dotfile_path
1446
+ per_file = self.class.dotfile_path_to_write_to
1433
1447
  file_utils.remove_entry_secure(out_dir) if File.exist?(out_dir)
1434
1448
  file_utils.remove_entry_secure(src_file) if File.exist?(src_file)
1435
1449
  file_utils.remove_entry_secure(per_file) if File.exist?(per_file)
@@ -1438,7 +1452,7 @@ if [__FILE__, '/usr/bin/rcov'].include?($PROGRAM_NAME) # ick
1438
1452
  def test_copy_one_file_almost_nothing_exist
1439
1453
  out_dir = tmpdir+'/out-dir'
1440
1454
  src_file = tmpdir+'/baz.txt'
1441
- per_file = self.class.dotfile_path
1455
+ per_file = self.class.dotfile_path_to_write_to
1442
1456
  file_utils.remove_entry_secure(out_dir) if File.exist?(out_dir)
1443
1457
  file_utils.remove_entry_secure(src_file) if File.exist?(src_file)
1444
1458
  if File.exist?(per_file)
data/test/test-for-doc.rb CHANGED
@@ -15,7 +15,7 @@ class String
15
15
  end
16
16
 
17
17
  describe 'TestForDoc' do
18
- NanDoc::SpecDoc.include_to(self)
18
+ include NanDoc::SpecDoc
19
19
  Treebis::PersistentDotfile.include_to(self, 'treebis.persistent.json')
20
20
 
21
21
  def prompt
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Chip Malice
@@ -14,25 +14,13 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-11 00:00:00 -04:00
17
+ date: 2010-05-17 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :runtime
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
33
- name: json
34
- prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
24
  requirements:
37
25
  - - ~>
38
26
  - !ruby/object:Gem::Version
@@ -42,8 +30,8 @@ dependencies:
42
30
  - 3
43
31
  version: 1.2.3
44
32
  type: :runtime
45
- version_requirements: *id002
46
- description: Treebis is a minimal, general scripting/task utility written in ruby that wraps common actions for moving, copying and altering filetrees. It is geared towards things like generators. It is comparable to a shell script that does a lot of mkdir, mv, cp commmands etc.
33
+ version_requirements: *id001
34
+ description: Treebis is a minimal, general scripting/task utility written in ruby that wraps common actions for moving, copying and altering filetrees. It is geared towards things like generators. It is comparable to a shell script that does a lot of mkdir, mv, cp commands etc.
47
35
  email: chip.malice@gmail.com
48
36
  executables: []
49
37
 
@@ -52,6 +40,7 @@ extensions: []
52
40
  extra_rdoc_files:
53
41
  - README
54
42
  files:
43
+ - NEWS.md
55
44
  - README
56
45
  - Rakefile
57
46
  - VERSION