fundler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf4fd7f898311c26d2c07fd92c2905846e68c746
4
+ data.tar.gz: a9ba71d7e459858563884adc3cb4f9bf139d9e64
5
+ SHA512:
6
+ metadata.gz: 8ec73e35ee9bfb8c3831431169eb6892b088c34d4c14d446cca4b458546d6b46b7a50f5099c61d65d765eb826decb77224da73aeaf6c0b479944c0659ea5c233
7
+ data.tar.gz: d4b53e33572b8e94c57cdf795770801ed271f28cac04777f2addfa1b7c7c14c064407c8c3197dede958827add23439c592c20e57df0a8ea4bc08e7d370008cbb
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in findler.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 zeroed
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Findler
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'findler'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install findler
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/fundler ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ # $: << File.expand_path('../../lib/', __FILE__) if File.directory?(File.expand_path('../../lib/', __FILE__))
5
+
6
+ require 'fundler'
7
+ require 'optparse'
8
+
9
+ class FundlerProgram
10
+ attr_accessor :output
11
+ attr_reader :input
12
+
13
+ def err msg
14
+ $stderr.puts "* error: #{msg}"
15
+ exit 1
16
+ end
17
+
18
+ def debug msg
19
+ $stderr.puts "* debug: #{msg}"
20
+ end
21
+
22
+ def fundler
23
+ @fundler ||= Fundler.new
24
+ end
25
+
26
+ def parse_options
27
+ # Defaults
28
+ @output = $stdout
29
+
30
+ # Parser
31
+ optparse = OptionParser.new do |opts|
32
+ opts.banner = "Usage: #{opts.program_name} [OPTIONS] "
33
+ opts.define_head 'file name cleaner'
34
+ opts.separator ''
35
+
36
+ opts.on('-d', '--debug', "Turn on debugging.") do
37
+ @debug = true
38
+ end
39
+
40
+ opts.on('-o', '--output FILE', String,
41
+ "Where to output the merged ruby script.") do |f|
42
+ @output = File.open(f, 'w') unless '-' == f
43
+ end
44
+
45
+ opts.on_tail('-V', '--version', 'Show the version.') do
46
+ $stderr.puts "#{opts.program_name} version: #{Fundler::VERSION}"
47
+ exit
48
+ end
49
+
50
+ opts.on_tail('-h', '--help', 'This Help.') do
51
+ $stderr.puts opts
52
+ exit
53
+ end
54
+ end
55
+
56
+ arguments = optparse.parse!
57
+
58
+ if arguments.size == 0
59
+ #err "You need to specify the directory"
60
+ elsif arguments.size > 1
61
+ err "You can only specify one directory a time"
62
+ end
63
+
64
+ if '-' == arguments.first
65
+ @input = $stdin
66
+ else
67
+ # @input = File.open(arguments.first, 'r')
68
+ end
69
+ end
70
+
71
+ def run
72
+ parse_options
73
+ debug "Pwd: #{fundler.pwd}"
74
+ debug "Input: #{input.inspect}"
75
+ debug "Output: #{output.inspect}"
76
+ # input_string = @input.read
77
+ # @input.close
78
+ # output_string = fundler.process(input_string)
79
+ # @output.write output_string
80
+ fundler.clean
81
+ end
82
+ end
83
+
84
+ #if __FILE__ == $0
85
+ p Time.now
86
+ FundlerProgram.new.run
87
+ #end
88
+
89
+ # EOF
data/bin/fundler~ ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ # $: << File.expand_path('../../lib/', __FILE__) if File.directory?(File.expand_path('../../lib/', __FILE__))
5
+
6
+ require 'findler'
7
+ require 'optparse'
8
+
9
+ class FindlerProgram
10
+ attr_accessor :output
11
+ attr_reader :input
12
+
13
+ def err msg
14
+ $stderr.puts "* error: #{msg}"
15
+ exit 1
16
+ end
17
+
18
+ def debug msg
19
+ $stderr.puts "* debug: #{msg}"
20
+ end
21
+
22
+ def findler
23
+ @findler ||= Findler.new
24
+ end
25
+
26
+ def parse_options
27
+ # Defaults
28
+ @output = $stdout
29
+
30
+ # Parser
31
+ optparse = OptionParser.new do |opts|
32
+ opts.banner = "Usage: #{opts.program_name} [OPTIONS] "
33
+ opts.define_head 'file name cleaner'
34
+ opts.separator ''
35
+
36
+ opts.on('-d', '--debug', "Turn on debugging.") do
37
+ @debug = true
38
+ end
39
+
40
+ opts.on('-o', '--output FILE', String,
41
+ "Where to output the merged ruby script.") do |f|
42
+ @output = File.open(f, 'w') unless '-' == f
43
+ end
44
+
45
+ opts.on_tail('-V', '--version', 'Show the version.') do
46
+ $stderr.puts "#{opts.program_name} version: #{Findler::VERSION}"
47
+ exit
48
+ end
49
+
50
+ opts.on_tail('-h', '--help', 'This Help.') do
51
+ $stderr.puts opts
52
+ exit
53
+ end
54
+ end
55
+
56
+ arguments = optparse.parse!
57
+
58
+ if arguments.size == 0
59
+ #err "You need to specify the directory"
60
+ elsif arguments.size > 1
61
+ err "You can only specify one directory a time"
62
+ end
63
+
64
+ if '-' == arguments.first
65
+ @input = $stdin
66
+ else
67
+ # @input = File.open(arguments.first, 'r')
68
+ end
69
+ end
70
+
71
+ def run
72
+ parse_options
73
+ debug "Pwd: #{findler.pwd}"
74
+ debug "Input: #{input.inspect}"
75
+ debug "Output: #{output.inspect}"
76
+ # input_string = @input.read
77
+ # @input.close
78
+ # output_string = findler.process(input_string)
79
+ # @output.write output_string
80
+ findler.clean
81
+ end
82
+ end
83
+
84
+ #if __FILE__ == $0
85
+ p Time.now
86
+ FindlerProgram.new.run
87
+ #end
88
+
89
+ # EOF
data/fundler.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fundler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fundler"
8
+ spec.version = Fundler::VERSION
9
+ spec.authors = ["zeroed"]
10
+ spec.email = ["edd.rossi@gmail.com"]
11
+ spec.description = 'just an humble find/rename utility'
12
+ spec.summary = 'find rename utility'
13
+ spec.homepage = "https://github.com/zeroed/findler"
14
+ spec.license = "GPL3"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/fundler.gemspec~ ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'findler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "findler"
8
+ spec.version = Findler::VERSION
9
+ spec.authors = ["zeroed"]
10
+ spec.email = ["edd.rossi@gmail.com"]
11
+ spec.description = 'just an humble find/rename utility'
12
+ spec.summary = 'find rename utility'
13
+ spec.homepage = "https://github.com/zeroed/findler"
14
+ spec.license = "GPL3"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,45 @@
1
+ 
2
+ module FindAndClean
3
+
4
+ # Finds all Ruby source files under the current or other supplied
5
+ # directory. A Ruby source file is defined as a file with the `.rb`
6
+ # extension or a file with no extension that has a ruby shebang line
7
+ # as its first line.
8
+ # @param root Root directory under which to search for
9
+ # ruby source files
10
+ # @return [Array] Array of filenames
11
+ def ruby_files(root = Dir.pwd)
12
+ files = Dir.open(root).reject { |file| FileTest.directory? file }
13
+ rb_files = []
14
+ rb_files << files.select { |file| File.extname(file) == '.rb' }
15
+ rb_files << files.select do |file|
16
+ File.extname(file) == '' &&
17
+ File.open(file) { |f| f.readline } =~ /#!.*ruby/
18
+ end
19
+ rb_files.flatten.sort
20
+ end
21
+
22
+ def all_files(root = Dir.pwd)
23
+ files = Dir.open(root).reject { |file| FileTest.directory? file }
24
+ files_found = files.select do |file|
25
+ file !=~ /^\./
26
+ end
27
+ files_found.sort
28
+ end
29
+
30
+ def clean_all_filenames(root = Dir.pwd)
31
+ renamed = []
32
+ self.all_files(root).each do |file|
33
+ new_name = file.downcase.gsub(/\s+/, '_')
34
+ File.rename(file, new_name)
35
+ renamed << new_name
36
+ end
37
+ renamed.count
38
+ end
39
+
40
+ def get_pwd
41
+ Dir.pwd
42
+ end
43
+
44
+ end #FindAndClean
45
+
@@ -0,0 +1,28 @@
1
+ # ---
2
+
3
+ require 'fileutils'
4
+ require 'rspec'
5
+
6
+ module ExitCodeMatchers
7
+ RSpec::Matchers.define :exit_with_code do |code|
8
+ actual = nil
9
+ match do |block|
10
+ begin
11
+ block.call
12
+ rescue SystemExit => e
13
+ actual = e.status
14
+ end
15
+ actual and actual == code
16
+ end
17
+ failure_message_for_should do |block|
18
+ "expected block to call exit(#{code}) but exit" +
19
+ (actual.nil? ? ' not called' : "(#{actual}) was called")
20
+ end
21
+ failure_message_for_should_not do |block|
22
+ "expected block not to call exit(#{code})"
23
+ end
24
+ description do
25
+ "expect block to call exit(#{code})"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+ class Fundler
3
+ # The version of the Fundler Utility.
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+ class Findler
3
+ # The version of the Findler Utility.
4
+ VERSION = "0.1.0"
5
+ end
data/lib/fundler.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'fundler/find_and_clean'
2
+
3
+ class Fundler
4
+ include FindAndClean
5
+ def clean
6
+ clean_all_filenames
7
+ end
8
+ def pwd
9
+ get_pwd
10
+ end
11
+ end
data/lib/fundler.rb~ ADDED
@@ -0,0 +1,11 @@
1
+ require 'findler/find_and_clean'
2
+
3
+ class Findler
4
+ include FindAndClean
5
+ def clean
6
+ clean_all_filenames
7
+ end
8
+ def pwd
9
+ get_pwd
10
+ end
11
+ end
@@ -0,0 +1,70 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'fundler'
5
+ require 'fundler/fundler_utils'
6
+
7
+ RSpec.configure do |config|
8
+ config.filter_run_excluding ruby: ->(v) { !RUBY_VERSION.start_with?(v.to_s) }
9
+ config.color_enabled = true
10
+ config.formatter = 'documentation'
11
+ # https://github.com/rspec/rspec-expectations
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect # disables `should`
14
+ end
15
+
16
+ config.include(ExitCodeMatchers)
17
+ end
18
+
19
+ class TestFundler
20
+ describe Fundler do
21
+ let(:finder) { Fundler.new }
22
+ before(:each) do
23
+ FileUtils::mkdir 'test'
24
+ File.open('test/example', 'w') do |f|
25
+ f.puts '#!/usr/bin/env ruby'
26
+ f.puts '# encoding: utf-8'
27
+ f.puts 'x = 0'
28
+ f.puts 'puts x'
29
+ end
30
+ File.open('test/example_rb.rb', 'w') do |f|
31
+ f.puts 'x = :foo'
32
+ f.puts 'puts x'
33
+ end
34
+ File.open('test/list.txt', 'w') do |f|
35
+ f.puts 'grocery list'
36
+ f.puts '- chunky bacon'
37
+ end
38
+ File.open('test/SpAcE cAmEl.txt', 'w') do |f|
39
+ f.puts 'foo!'
40
+ end
41
+ end
42
+ after(:each) do
43
+ FileUtils::rm_rf 'test'
44
+ end
45
+
46
+ it 'finds all files' do
47
+ FileUtils::cd './test' do
48
+ expect(finder.all_files()).to eq(['example', 'example_rb.rb', 'list.txt', 'SpAcE cAmEl.txt'].sort)
49
+ end
50
+ end
51
+ it 'finds a file with no .rb extension but has a shebang line' do
52
+ FileUtils::cd './test' do
53
+ expect(finder.ruby_files()).to eq(['example', 'example_rb.rb'])
54
+ end
55
+ end
56
+ it 'clean all filenames' do
57
+ FileUtils::cd './test' do
58
+ expect(finder.clean_all_filenames()).to eq(4)
59
+ expect(finder.all_files()).to eq(['example', 'example_rb.rb', 'list.txt', 'space_camel.txt'].sort)
60
+ end
61
+ end
62
+ it 'show the pwd (last dir in this spec)' do
63
+ FileUtils::cd './test' do
64
+ expect(finder.get_pwd.split('/').last).to eq('test')
65
+ end
66
+ end
67
+
68
+ end # describe
69
+
70
+ end #TestFundler
@@ -0,0 +1,70 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'fundler'
5
+ require 'fundler/findler_utils'
6
+
7
+ RSpec.configure do |config|
8
+ config.filter_run_excluding ruby: ->(v) { !RUBY_VERSION.start_with?(v.to_s) }
9
+ config.color_enabled = true
10
+ config.formatter = 'documentation'
11
+ # https://github.com/rspec/rspec-expectations
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect # disables `should`
14
+ end
15
+
16
+ config.include(ExitCodeMatchers)
17
+ end
18
+
19
+ class TestFundler
20
+ describe Fundler do
21
+ let(:finder) { Fundler.new }
22
+ before(:each) do
23
+ FileUtils::mkdir 'test'
24
+ File.open('test/example', 'w') do |f|
25
+ f.puts '#!/usr/bin/env ruby'
26
+ f.puts '# encoding: utf-8'
27
+ f.puts 'x = 0'
28
+ f.puts 'puts x'
29
+ end
30
+ File.open('test/example_rb.rb', 'w') do |f|
31
+ f.puts 'x = :foo'
32
+ f.puts 'puts x'
33
+ end
34
+ File.open('test/list.txt', 'w') do |f|
35
+ f.puts 'grocery list'
36
+ f.puts '- chunky bacon'
37
+ end
38
+ File.open('test/SpAcE cAmEl.txt', 'w') do |f|
39
+ f.puts 'foo!'
40
+ end
41
+ end
42
+ after(:each) do
43
+ FileUtils::rm_rf 'test'
44
+ end
45
+
46
+ it 'finds all files' do
47
+ FileUtils::cd './test' do
48
+ expect(finder.all_files()).to eq(['example', 'example_rb.rb', 'list.txt', 'SpAcE cAmEl.txt'].sort)
49
+ end
50
+ end
51
+ it 'finds a file with no .rb extension but has a shebang line' do
52
+ FileUtils::cd './test' do
53
+ expect(finder.ruby_files()).to eq(['example', 'example_rb.rb'])
54
+ end
55
+ end
56
+ it 'clean all filenames' do
57
+ FileUtils::cd './test' do
58
+ expect(finder.clean_all_filenames()).to eq(4)
59
+ expect(finder.all_files()).to eq(['example', 'example_rb.rb', 'list.txt', 'space_camel.txt'].sort)
60
+ end
61
+ end
62
+ it 'show the pwd (last dir in this spec)' do
63
+ FileUtils::cd './test' do
64
+ expect(finder.get_pwd.split('/').last).to eq('test')
65
+ end
66
+ end
67
+
68
+ end # describe
69
+
70
+ end #TestFundler
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fundler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - zeroed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: just an humble find/rename utility
42
+ email:
43
+ - edd.rossi@gmail.com
44
+ executables:
45
+ - fundler
46
+ - fundler~
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/fundler
56
+ - bin/fundler~
57
+ - fundler.gemspec
58
+ - fundler.gemspec~
59
+ - lib/fundler.rb
60
+ - lib/fundler.rb~
61
+ - lib/fundler/find_and_clean.rb
62
+ - lib/fundler/fundler_utils.rb
63
+ - lib/fundler/version.rb
64
+ - lib/fundler/version.rb~
65
+ - spec/fundler_spec.rb
66
+ - spec/fundler_spec.rb~
67
+ homepage: https://github.com/zeroed/findler
68
+ licenses:
69
+ - GPL3
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.0.3
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: find rename utility
91
+ test_files:
92
+ - spec/fundler_spec.rb
93
+ - spec/fundler_spec.rb~
94
+ has_rdoc: