dir_dsl 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDUwNjVmYzc1MmIyYjNjNzFkZWQ5OGJiMzY1MTNjZjk3NDE5ZTU5OQ==
4
+ MzE5NmM3YjgxNjFiNzA2NWVmZThhNjk2NmM1NWFjMjE1NmZiZWFiMw==
5
5
  data.tar.gz: !binary |-
6
- NmFkOGM0NWNkOTRkM2IzNDU1OWYzZTM1ZDZiZmI5MzhjN2Q3MGQyYg==
6
+ NGUzNjZjMGJlZjgyNDY3ODNjM2IwMTJkMjMxOGQyN2ViZjgwMTYyNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWU3YWZkNDYwYjc0ZWM4YmM0MDA0MTg3MjYyMjBlOGViNDVjODk0ZDcwZDY3
10
- YWQ1MjljZTNlZjU2OTQ3YmQ1MmYyZWZlMjFiMjk3Mjc0MThlZjY2MmU4ZDUw
11
- ZGE0MTYwZTdjMzNjMmY5MTE3NTc3NDViOGM2YjA5ZjdjNTYxZTU=
9
+ N2ZjNWQ2NWYwOTBhMDIwMmM3YTM5YWFiYjgwYjhiZjUwMWI4MTYwODdkZmQw
10
+ N2U2MzgzZmY0ZGRjMDkxYWYyZTRmMjUwNmE5OTZlMTBkMjBjYzk5NjMyNTIx
11
+ NTAyZDA2ZTMyYTI4NWEyMDljNTFmMTcwYzQyNWNjNDVkMGVhNGU=
12
12
  data.tar.gz: !binary |-
13
- NGEwOTE0YjU0MGIxMjczNWQzNzZmYWE2OTc5NjE1OTI5NjQyNTQ5NTQ3ZGRl
14
- YmZkYTExN2U1Y2Y2ZTczZDc5MWEwYzE1OTUxYjMzYmE0ODk1YmZmMWZhNjNj
15
- YzMxNjE1ZjNkMzdjYjA1OWU5ZTNjZWE2MmM5ZDJmNGY4Y2FlNzQ=
13
+ YThlYWYzZTE2YmIxMjgwZTJiZWVhYzI1OTNlZWZkNjBiMGM0ODE0N2RmZWFh
14
+ Yzk1NmY0NDA4OWE4MmIxMTM3ODk2MWE5Njg0ZWUwNzc1MTZhZjkxYWYxZTI2
15
+ MzBmODE1ZjhhMmY5NDY2ODQ2MzAyZjlhZjk4YWFjMWYzMzI4OGY=
data/.idea/dir_dsl.iml CHANGED
@@ -18,7 +18,6 @@
18
18
  <orderEntry type="library" scope="PROVIDED" name="file_utils (v1.0.7, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
19
19
  <orderEntry type="library" scope="PROVIDED" name="gemcutter (v0.7.1, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
20
20
  <orderEntry type="library" scope="PROVIDED" name="gemspec_deps_gen (v1.1.2, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
21
- <orderEntry type="library" scope="PROVIDED" name="meta_methods (v1.0.5, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
22
21
  <orderEntry type="library" scope="PROVIDED" name="metaclass (v0.0.1, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
23
22
  <orderEntry type="library" scope="PROVIDED" name="mocha (v0.14.0, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
24
23
  <orderEntry type="library" scope="PROVIDED" name="rspec (v2.14.1, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
data/CHANGES CHANGED
@@ -3,3 +3,7 @@
3
3
  == Version 1.0.0
4
4
 
5
5
  * Initial release.
6
+
7
+ == Version 1.0.1
8
+
9
+ * Bug fixes.
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  group :default do
4
- gem "meta_methods"
5
4
  gem "file_utils"
6
5
  end
7
6
 
data/Gemfile.lock CHANGED
@@ -7,7 +7,6 @@ GEM
7
7
  gemspec_deps_gen (1.1.2)
8
8
  bundler
9
9
  file_utils
10
- meta_methods (1.0.5)
11
10
  metaclass (0.0.1)
12
11
  mocha (0.14.0)
13
12
  metaclass (~> 0.0.1)
@@ -27,6 +26,5 @@ DEPENDENCIES
27
26
  file_utils
28
27
  gemcutter
29
28
  gemspec_deps_gen
30
- meta_methods
31
29
  mocha
32
30
  rspec
data/Rakefile CHANGED
@@ -35,3 +35,8 @@ RSpec::Core::RakeTask.new do |task|
35
35
  task.pattern = 'spec/**/*_spec.rb'
36
36
  task.verbose = false
37
37
  end
38
+
39
+ task :fix_debug do
40
+ system "mkdir -p $GEM_HOME/gems/debugger-ruby_core_source-1.2.3/lib"
41
+ system "cp -R ~/debugger-ruby_core_source/lib $GEM_HOME/gems/debugger-ruby_core_source-1.2.3"
42
+ end
data/dir_dsl.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/lib/dir_dsl/version')
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dir_dsl"
7
+ spec.summary = %q{Library for working with files and directories file in DSL-way }
8
+ spec.description = %q{Library for working with files and directories in DSL-way }
9
+ spec.email = "alexander.shvets@gmail.com"
10
+ spec.authors = ["Alexander Shvets"]
11
+ spec.homepage = "http://github.com/shvets/dir_dsl"
12
+
13
+ spec.files = `git ls-files`.split($\)
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+ spec.version = DirDSL::VERSION
17
+
18
+
19
+ spec.add_runtime_dependency "file_utils", [">= 0"]
20
+ spec.add_development_dependency "gemspec_deps_gen", [">= 0"]
21
+ spec.add_development_dependency "gemcutter", [">= 0"]
22
+
23
+ end
24
+
@@ -1,27 +1,25 @@
1
1
  require 'file_utils/file_utils'
2
- require 'meta_methods'
3
2
 
4
3
  class DirDSL
5
4
  include FileUtils
6
- include MetaMethods
7
5
 
8
- def initialize name, basedir
9
- @name = name
10
- @basedir = File.expand_path(basedir)
11
- end
6
+ attr_reader :from_root, :to_root
12
7
 
13
- def build(name=nil, &execute_block)
14
- name = name.nil? ? @name : name
8
+ def initialize from_root, to_root
9
+ @from_root = File.expand_path(from_root)
10
+ @to_root = File.expand_path(to_root)
11
+ end
15
12
 
16
- evaluate_dsl(self, nil, execute_block)
13
+ def build(&block)
14
+ self.instance_eval(&block)
17
15
  end
18
16
 
19
17
  def entry_exist? entry_name
20
- File.exist? full_name("#@name/#{entry_name}")
18
+ File.exist? "#{to_root}/#{entry_name}"
21
19
  end
22
20
 
23
21
  def entries_size
24
- list = Dir.glob("#{full_name(@name)}/**/*")
22
+ list = Dir.glob("#{to_root}/**/*")
25
23
 
26
24
  cnt = 0
27
25
  list.each do |name|
@@ -32,19 +30,19 @@ class DirDSL
32
30
  end
33
31
 
34
32
  def list dir="."
35
- list = pattern_to_files full_name("#@name/#{dir}"), "**/*"
33
+ list = pattern_to_files"#{from_root}/#{dir}", "**/*"
36
34
 
37
35
  list.each_with_index do |name, index|
38
- list[index] = name[full_name("#@name/#{dir}").length+1..-1]
36
+ list[index] = name["#{from_root}/#{dir}".length+1..-1]
39
37
  end
40
38
  end
41
39
 
42
40
  def file params
43
- to_dir = to_dir(params[:name], params[:to_dir])
41
+ to_dir = to_dir(params[:to_dir], params[:name])
44
42
 
45
- create_directory full_name(to_dir)
43
+ create_directory to_dir unless File.exist? to_dir
46
44
 
47
- write_to_file full_name(params[:name]), full_name("#{to_dir}/#{File.basename(params[:name])}")
45
+ write_to_file "#{from_root}/#{params[:name]}", "#{to_dir}/#{File.basename(params[:name])}"
48
46
  end
49
47
 
50
48
  def content params
@@ -53,52 +51,42 @@ class DirDSL
53
51
  stream = source.kind_of?(String) ? StringIO.new(source) : source
54
52
  content = stream.read
55
53
 
56
- to_dir = to_dir(params[:name], params[:to_dir])
54
+ to_dir = to_dir(params[:to_dir], params[:name])
57
55
 
58
- create_directory full_name(to_dir)
56
+ create_directory to_dir unless File.exist? to_dir
59
57
 
60
- write_content_to_file content, full_name("#{to_dir}/#{File.basename(params[:name])}")
58
+ write_content_to_file content, "#{to_dir}/#{File.basename(params[:name])}"
61
59
  end
62
60
 
63
61
  def directory params
64
62
  if params[:from_dir].nil?
65
- create_empty_directory params[:to_dir]
63
+ to_dir = "#{to_root}/#{params[:to_dir]}"
64
+
65
+ create_directory to_dir unless File.exist? to_dir
66
66
  else
67
67
  if params[:to_dir] == "." || params[:to_dir].nil?
68
- to_dir = "#@name"
68
+ to_dir = params[:from_dir]
69
69
  else
70
- to_dir = "#@name/#{params[:to_dir]}"
70
+ to_dir = params[:to_dir]
71
71
  end
72
72
 
73
73
  filter = params[:filter].nil? ? "**/*" : params[:filter]
74
74
 
75
- copy_files full_name(params[:from_dir]), full_name(to_dir), filter
75
+ copy_files "#{from_root}/#{params[:from_dir]}", "#{to_root}/#{to_dir}", filter
76
76
  end
77
77
  end
78
78
 
79
79
  private
80
80
 
81
- def to_dir name, dir
81
+ def to_dir dir, name
82
82
  if dir.nil?
83
83
  from_dir = File.dirname(name)
84
- (from_dir == ".") ? @name : "#@name/#{from_dir}"
84
+ to_dir = (from_dir == ".") ? to_root : "#{to_root}/#{from_dir}"
85
85
  else
86
- (dir == ".") ? @name : "#@name/#{dir}"
86
+ to_dir = (dir == ".") ? to_root : "#{to_root}/#{dir}"
87
87
  end
88
- end
89
-
90
- def create_empty_directory dir
91
- to_dir = (dir == ".") ? @name : "#@name/#{dir}"
92
-
93
- create_directory full_name(to_dir)
94
- end
95
-
96
- def full_name? name
97
- File.expand_path(name) == name
98
- end
99
88
 
100
- def full_name name
101
- full_name?(name) ? name : "#@basedir/#{name}"
89
+ to_dir
102
90
  end
103
91
 
104
92
  end
@@ -1,3 +1,3 @@
1
1
  class DirDSL
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/spec/dir_dsl_spec.rb CHANGED
@@ -6,12 +6,13 @@ require 'file_utils/file_utils'
6
6
  describe DirDSL do
7
7
  include FileUtils
8
8
 
9
- let(:basedir) { "#{File.dirname(__FILE__)}/.." }
9
+ let(:from_basedir) { "#{File.dirname(__FILE__)}/.." }
10
+ let(:to_basedir) { "#{File.dirname(__FILE__)}/../build" }
10
11
 
11
- subject { DirDSL.new("build/test", basedir) }
12
+ subject { DirDSL.new(from_basedir, to_basedir) }
12
13
 
13
14
  after do
14
- delete_directory "#{basedir}/build"
15
+ delete_directory "#{to_basedir}"
15
16
  end
16
17
 
17
18
  it "should create new directory with files at particular folder" do
@@ -38,7 +39,7 @@ describe DirDSL do
38
39
  end
39
40
 
40
41
  it "should create new directory with file created from file" do
41
- src = File.open("#{basedir}/Rakefile")
42
+ src = File.open("#{from_basedir}/Rakefile")
42
43
  subject.build do
43
44
  content :name => "Rakefile", :source => src
44
45
  end
@@ -68,7 +69,7 @@ describe DirDSL do
68
69
  directory :from_dir => "spec"
69
70
  end
70
71
 
71
- subject.list.should include "spec_helper.rb"
72
+ subject.list("spec").should include "spec_helper.rb"
72
73
  end
73
74
 
74
75
  it "should display files in specified subdirectory" do
@@ -76,7 +77,7 @@ describe DirDSL do
76
77
  directory :from_dir => "lib"
77
78
  end
78
79
 
79
- subject.list("dir_dsl").first.should =~ %r{dir_dsl.rb}
80
+ subject.list("lib/dir_dsl").first.should =~ %r{dir_dsl.rb}
80
81
  end
81
82
 
82
83
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dir_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-30 00:00:00.000000000 Z
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: meta_methods
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: file_utils
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +75,7 @@ files:
89
75
  - LICENSE
90
76
  - README.md
91
77
  - Rakefile
78
+ - dir_dsl.gemspec
92
79
  - dir_dsl.gemspec.erb
93
80
  - lib/dir_dsl.rb
94
81
  - lib/dir_dsl/dir_dsl.rb