dir_dsl 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDUwNjVmYzc1MmIyYjNjNzFkZWQ5OGJiMzY1MTNjZjk3NDE5ZTU5OQ==
5
+ data.tar.gz: !binary |-
6
+ NmFkOGM0NWNkOTRkM2IzNDU1OWYzZTM1ZDZiZmI5MzhjN2Q3MGQyYg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWU3YWZkNDYwYjc0ZWM4YmM0MDA0MTg3MjYyMjBlOGViNDVjODk0ZDcwZDY3
10
+ YWQ1MjljZTNlZjU2OTQ3YmQ1MmYyZWZlMjFiMjk3Mjc0MThlZjY2MmU4ZDUw
11
+ ZGE0MTYwZTdjMzNjMmY5MTE3NTc3NDViOGM2YjA5ZjdjNTYxZTU=
12
+ data.tar.gz: !binary |-
13
+ NGEwOTE0YjU0MGIxMjczNWQzNzZmYWE2OTc5NjE1OTI5NjQyNTQ5NTQ3ZGRl
14
+ YmZkYTExN2U1Y2Y2ZTczZDc5MWEwYzE1OTUxYjMzYmE0ODk1YmZmMWZhNjNj
15
+ YzMxNjE1ZjNkMzdjYjA1OWU5ZTNjZWE2MmM5ZDJmNGY4Y2FlNzQ=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.idea/.name ADDED
@@ -0,0 +1 @@
1
+ dir_dsl
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
data/.idea/dir_dsl.iml ADDED
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager">
13
+ <content url="file://$MODULE_DIR$" />
14
+ <orderEntry type="inheritedJdk" />
15
+ <orderEntry type="sourceFolder" forTests="false" />
16
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.5, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.4, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="file_utils (v1.0.7, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="gemcutter (v0.7.1, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
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
+ <orderEntry type="library" scope="PROVIDED" name="metaclass (v0.0.1, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="mocha (v0.14.0, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v2.14.1, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.14.5, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v2.14.3, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v2.14.3, RVM: ruby-1.9.3-p448 [dir_dsl]) [gem]" level="application" />
28
+ </component>
29
+ </module>
30
+
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
+ </project>
5
+
data/.idea/misc.xml ADDED
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.3-p448 [dir_dsl]" project-jdk-type="RUBY_SDK" />
4
+ </project>
5
+
data/.idea/modules.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/dir_dsl.iml" filepath="$PROJECT_DIR$/.idea/dir_dsl.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
9
+
@@ -0,0 +1,5 @@
1
+ <component name="DependencyValidationManager">
2
+ <state>
3
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
4
+ </state>
5
+ </component>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
7
+
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ dir_dsl
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3
data/CHANGES ADDED
@@ -0,0 +1,5 @@
1
+ = Dir DSL
2
+
3
+ == Version 1.0.0
4
+
5
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :default do
4
+ gem "meta_methods"
5
+ gem "file_utils"
6
+ end
7
+
8
+ group :development do
9
+ gem "gemspec_deps_gen"
10
+ gem "gemcutter"
11
+ end
12
+
13
+ group :test do
14
+ gem "rspec"
15
+ gem "mocha"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.4)
5
+ file_utils (1.0.7)
6
+ gemcutter (0.7.1)
7
+ gemspec_deps_gen (1.1.2)
8
+ bundler
9
+ file_utils
10
+ meta_methods (1.0.5)
11
+ metaclass (0.0.1)
12
+ mocha (0.14.0)
13
+ metaclass (~> 0.0.1)
14
+ rspec (2.14.1)
15
+ rspec-core (~> 2.14.0)
16
+ rspec-expectations (~> 2.14.0)
17
+ rspec-mocks (~> 2.14.0)
18
+ rspec-core (2.14.5)
19
+ rspec-expectations (2.14.3)
20
+ diff-lcs (>= 1.1.3, < 2.0)
21
+ rspec-mocks (2.14.3)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ file_utils
28
+ gemcutter
29
+ gemspec_deps_gen
30
+ meta_methods
31
+ mocha
32
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Alexander Shvets
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ dir_dsl
2
+ =======
3
+
4
+ Library for working with files and directories (create, copy) in DSL-way
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env rake
2
+
3
+ $LOAD_PATH.unshift File.expand_path("lib", File.dirname(__FILE__))
4
+
5
+ require "rspec/core/rake_task"
6
+ require "dir_dsl/version"
7
+ require "gemspec_deps_gen/gemspec_deps_gen"
8
+
9
+ version = DirDSL::VERSION
10
+ project_name = File.basename(Dir.pwd)
11
+
12
+ task :gen do
13
+ generator = GemspecDepsGen.new
14
+
15
+ generator.generate_dependencies "spec", "#{project_name}.gemspec.erb", "#{project_name}.gemspec"
16
+ end
17
+
18
+ task :build => :gen do
19
+ system "gem build #{project_name}.gemspec"
20
+ end
21
+
22
+ task :install do
23
+ system "gem install #{project_name}-#{version}.gem"
24
+ end
25
+
26
+ task :uninstall do
27
+ system "gem uninstall #{project_name}"
28
+ end
29
+
30
+ task :release => :build do
31
+ system "gem push #{project_name}-#{version}.gem"
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new do |task|
35
+ task.pattern = 'spec/**/*_spec.rb'
36
+ task.verbose = false
37
+ end
@@ -0,0 +1,20 @@
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
+ <%= project_dependencies %>
19
+ end
20
+
@@ -0,0 +1,105 @@
1
+ require 'file_utils/file_utils'
2
+ require 'meta_methods'
3
+
4
+ class DirDSL
5
+ include FileUtils
6
+ include MetaMethods
7
+
8
+ def initialize name, basedir
9
+ @name = name
10
+ @basedir = File.expand_path(basedir)
11
+ end
12
+
13
+ def build(name=nil, &execute_block)
14
+ name = name.nil? ? @name : name
15
+
16
+ evaluate_dsl(self, nil, execute_block)
17
+ end
18
+
19
+ def entry_exist? entry_name
20
+ File.exist? full_name("#@name/#{entry_name}")
21
+ end
22
+
23
+ def entries_size
24
+ list = Dir.glob("#{full_name(@name)}/**/*")
25
+
26
+ cnt = 0
27
+ list.each do |name|
28
+ cnt += 1 if File.file?(name)
29
+ end
30
+
31
+ cnt
32
+ end
33
+
34
+ def list dir="."
35
+ list = pattern_to_files full_name("#@name/#{dir}"), "**/*"
36
+
37
+ list.each_with_index do |name, index|
38
+ list[index] = name[full_name("#@name/#{dir}").length+1..-1]
39
+ end
40
+ end
41
+
42
+ def file params
43
+ to_dir = to_dir(params[:name], params[:to_dir])
44
+
45
+ create_directory full_name(to_dir)
46
+
47
+ write_to_file full_name(params[:name]), full_name("#{to_dir}/#{File.basename(params[:name])}")
48
+ end
49
+
50
+ def content params
51
+ source = params[:source]
52
+
53
+ stream = source.kind_of?(String) ? StringIO.new(source) : source
54
+ content = stream.read
55
+
56
+ to_dir = to_dir(params[:name], params[:to_dir])
57
+
58
+ create_directory full_name(to_dir)
59
+
60
+ write_content_to_file content, full_name("#{to_dir}/#{File.basename(params[:name])}")
61
+ end
62
+
63
+ def directory params
64
+ if params[:from_dir].nil?
65
+ create_empty_directory params[:to_dir]
66
+ else
67
+ if params[:to_dir] == "." || params[:to_dir].nil?
68
+ to_dir = "#@name"
69
+ else
70
+ to_dir = "#@name/#{params[:to_dir]}"
71
+ end
72
+
73
+ filter = params[:filter].nil? ? "**/*" : params[:filter]
74
+
75
+ copy_files full_name(params[:from_dir]), full_name(to_dir), filter
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ def to_dir name, dir
82
+ if dir.nil?
83
+ from_dir = File.dirname(name)
84
+ (from_dir == ".") ? @name : "#@name/#{from_dir}"
85
+ else
86
+ (dir == ".") ? @name : "#@name/#{dir}"
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
+
100
+ def full_name name
101
+ full_name?(name) ? name : "#@basedir/#{name}"
102
+ end
103
+
104
+ end
105
+
@@ -0,0 +1,3 @@
1
+ class DirDSL
2
+ VERSION = "1.0.0"
3
+ end
data/lib/dir_dsl.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'dir_dsl/dir_dsl'
2
+
@@ -0,0 +1,82 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'dir_dsl'
4
+ require 'file_utils/file_utils'
5
+
6
+ describe DirDSL do
7
+ include FileUtils
8
+
9
+ let(:basedir) { "#{File.dirname(__FILE__)}/.." }
10
+
11
+ subject { DirDSL.new("build/test", basedir) }
12
+
13
+ after do
14
+ delete_directory "#{basedir}/build"
15
+ end
16
+
17
+ it "should create new directory with files at particular folder" do
18
+ subject.build do
19
+ file :name => "Gemfile"
20
+ file :name => "Rakefile", :to_dir => "my_config"
21
+ file :name => "spec/spec_helper.rb", :to_dir => "my_config"
22
+ end
23
+
24
+ subject.entry_exist?("Gemfile").should be_true
25
+ subject.entry_exist?("my_config/Rakefile").should be_true
26
+ subject.entry_exist?("my_config/spec_helper.rb").should be_true
27
+
28
+ subject.entries_size.should == 3
29
+ end
30
+
31
+ it "should create new directory with file created from string" do
32
+ subject.build do
33
+ content :name => "README", :source => "My README file content"
34
+ end
35
+
36
+ subject.entry_exist?("README").should be_true
37
+ subject.entries_size.should == 1
38
+ end
39
+
40
+ it "should create new directory with file created from file" do
41
+ src = File.open("#{basedir}/Rakefile")
42
+ subject.build do
43
+ content :name => "Rakefile", :source => src
44
+ end
45
+
46
+ subject.entry_exist?("Rakefile").should be_true
47
+ subject.entries_size.should == 1
48
+ end
49
+
50
+ it "should create new directory with new empty folder" do
51
+ subject.build do
52
+ directory :to_dir => "my_config"
53
+ end
54
+
55
+ subject.entry_exist?("my_config").should be_true
56
+ end
57
+
58
+ it "should create new directory with new folder" do
59
+ subject.build do
60
+ directory :from_dir => "config", :to_dir => "my_config"
61
+ end
62
+
63
+ subject.entry_exist?("my_config").should be_true
64
+ end
65
+
66
+ it "should display files in current directory" do
67
+ subject.build do
68
+ directory :from_dir => "spec"
69
+ end
70
+
71
+ subject.list.should include "spec_helper.rb"
72
+ end
73
+
74
+ it "should display files in specified subdirectory" do
75
+ subject.build do
76
+ directory :from_dir => "lib"
77
+ end
78
+
79
+ subject.list("dir_dsl").first.should =~ %r{dir_dsl.rb}
80
+ end
81
+
82
+ end
@@ -0,0 +1 @@
1
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dir_dsl
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Shvets
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-30 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: file_utils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gemspec_deps_gen
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gemcutter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ! 'Library for working with files and directories in DSL-way '
70
+ email: alexander.shvets@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - .gitignore
76
+ - .idea/.name
77
+ - .idea/.rakeTasks
78
+ - .idea/dir_dsl.iml
79
+ - .idea/encodings.xml
80
+ - .idea/misc.xml
81
+ - .idea/modules.xml
82
+ - .idea/scopes/scope_settings.xml
83
+ - .idea/vcs.xml
84
+ - .ruby-gemset
85
+ - .ruby-version
86
+ - CHANGES
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - dir_dsl.gemspec.erb
93
+ - lib/dir_dsl.rb
94
+ - lib/dir_dsl/dir_dsl.rb
95
+ - lib/dir_dsl/version.rb
96
+ - spec/dir_dsl_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: http://github.com/shvets/dir_dsl
99
+ licenses: []
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.1.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Library for working with files and directories file in DSL-way
121
+ test_files:
122
+ - spec/dir_dsl_spec.rb
123
+ - spec/spec_helper.rb