copymachine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@copymachine --create
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in copy_machine.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rspec'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 PatrickMa
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
+ # CopyMachine
2
+
3
+ Copyright your Ruby files with (super) ease.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'copy_machine'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install copy_machine
18
+
19
+ ## Usage
20
+
21
+ `cm .`
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 'Added 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,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/cm ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/copy_machine'
4
+
5
+ target_path = ARGV[0]
6
+ puts "Copywriting #{target_path}..."
7
+ CopyMachine.new(target_path).copyright!
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/copy_machine/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["PatrickMa"]
6
+ gem.email = ["patrick@multichannel.net"]
7
+ gem.description = %q{Copyright your Ruby files with ease.}
8
+ gem.summary = %q{A command-line recursive Ruby file copyrighter.}
9
+ gem.homepage = "https://github.com/PatrickMa/CopyMachine"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(spec)/})
14
+ gem.name = "copymachine"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = CopyMachine::VERSION
17
+ end
@@ -0,0 +1,53 @@
1
+ require_relative "copy_machine/version"
2
+ require_relative 'text_utils'
3
+
4
+ class CopyMachine
5
+ class << self
6
+ include TextUtils
7
+
8
+ def MESSAGE
9
+ [
10
+ ('#' * 80),
11
+ ('#' * 80),
12
+ surround('Copyright (c) 2012 Multichannel Research Ltd. All rights reserved.', '#'),
13
+ ('#' * 80),
14
+ ('#' * 80)
15
+ ].join("\n") + "\n"
16
+ end
17
+ end
18
+
19
+ def initialize(target_path)
20
+ @target_path = target_path
21
+ end
22
+
23
+ def copyright!
24
+ Dir.glob("#{@target_path}/**/*.rb").each do |file|
25
+ copyright_file!(file)
26
+ end
27
+ end
28
+
29
+ def copyright_file!(path)
30
+ @path = path
31
+ new_output = CopyMachine.MESSAGE + file_contents
32
+ write_results!(new_output) unless has_copyright?
33
+ end
34
+
35
+ private
36
+
37
+ def has_copyright?
38
+ file_contents.include?(CopyMachine.MESSAGE)
39
+ end
40
+
41
+ def file_contents
42
+ file = File.open(@path, 'r')
43
+ file.read.tap do
44
+ file.close
45
+ end
46
+ end
47
+
48
+ def write_results!(results)
49
+ file = File.open(@path, 'w')
50
+ file.write(results)
51
+ file.close
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ class CopyMachine
2
+ VERSION = "0.0.1"
3
+ end
data/lib/text_utils.rb ADDED
@@ -0,0 +1,7 @@
1
+ module TextUtils
2
+ def surround(text, pattern, length = 80)
3
+ left = (length - text.length - 2) / 2
4
+ right = left + (length - text.length - 2) % 2
5
+ pattern + (' ' * left) + text + (' ' * right) + pattern
6
+ end
7
+ end
data/spec/cm_spec.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "cm" do
4
+ before do
5
+ `mkdir #{ASSETS}`
6
+ `touch #{ASSETS}/dummy.rb`
7
+ end
8
+
9
+ it "can copywrite files in a target folder" do
10
+ puts `bin/cm #{ASSETS}`
11
+ results = `cat #{ASSETS}/dummy.rb`
12
+ lines = results.split("\n")
13
+ lines[0].should == ('#' * 80)
14
+ lines[1].should == ('#' * 80)
15
+ lines[2].should == surround('Copyright (c) 2012 Multichannel Research Ltd. All rights reserved.', '#')
16
+ lines[3].should == ('#' * 80)
17
+ lines[4].should == ('#' * 80)
18
+ end
19
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require './lib/copy_machine'
3
+
4
+ describe CopyMachine do
5
+ before do
6
+ `mkdir #{ASSETS}`
7
+ `mkdir #{ASSETS}/recursive`
8
+ `touch #{dummy_file}`
9
+ `touch #{recursive_file}`
10
+ `touch #{ASSETS}/README`
11
+ end
12
+
13
+ let(:dummy_file) { "#{ASSETS}/dummy.rb"}
14
+ let(:recursive_file) { "#{ASSETS}/recursive/dummy.rb"}
15
+ let(:results) { `cat #{dummy_file}` }
16
+
17
+ subject { CopyMachine.new(ASSETS) }
18
+
19
+ describe "#copyright!" do
20
+ it "runs #copyright_file! on all Ruby files" do
21
+ subject.should_receive(:copyright_file!).twice
22
+ subject.should_not_receive(:copyright_file!).with("#{ASSETS}/README")
23
+ subject.copyright!
24
+ end
25
+
26
+ it "runs recursively"
27
+ end
28
+
29
+ describe "#copyright_file!(path)" do
30
+ it "prepends the copyright notice" do
31
+ subject.copyright_file!(dummy_file)
32
+ end
33
+
34
+ it "prepends the content" do
35
+ content = "class Car\nend\n"
36
+ file = File.open(dummy_file, 'w')
37
+ file.write(content)
38
+ file.close
39
+
40
+ subject.copyright_file!(dummy_file)
41
+ results.should match(content)
42
+ end
43
+
44
+ it "won't duplicate the copywrite message" do
45
+ subject.copyright_file!(dummy_file)
46
+ subject.copyright_file!(dummy_file)
47
+ results.should_not match(CopyMachine.MESSAGE * 2)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe TextUtils do
4
+ describe "#surround(text, pattern, length = 80)" do
5
+ it "centers the text with pattern to make a length" do
6
+ results = surround('hello', '#')
7
+ results.should == '#' + (' ' * 36) + 'hello' + (' ' * 37) + '#'
8
+ results = surround('Multichannel Research Limited', '#')
9
+ results.should == '#' + (' ' * 24) + 'Multichannel Research Limited' + (' ' * 25) + '#'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ ASSETS = 'spec/assets'
2
+
3
+ RSpec.configure do |c|
4
+ require './lib/text_utils'
5
+ include TextUtils
6
+
7
+ c.after do
8
+ `rm -Rf #{ASSETS}`
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: copymachine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - PatrickMa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Copyright your Ruby files with ease.
15
+ email:
16
+ - patrick@multichannel.net
17
+ executables:
18
+ - cm
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - .rvmrc
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - bin/cm
30
+ - copymachine.gemspec
31
+ - lib/copy_machine.rb
32
+ - lib/copy_machine/version.rb
33
+ - lib/text_utils.rb
34
+ - spec/cm_spec.rb
35
+ - spec/lib/copy_machine_spec.rb
36
+ - spec/lib/text_utils_spec.rb
37
+ - spec/spec_helper.rb
38
+ homepage: https://github.com/PatrickMa/CopyMachine
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: A command-line recursive Ruby file copyrighter.
62
+ test_files:
63
+ - spec/cm_spec.rb
64
+ - spec/lib/copy_machine_spec.rb
65
+ - spec/lib/text_utils_spec.rb
66
+ - spec/spec_helper.rb