Permalink
Browse files

Removed needless white spaces

  • Loading branch information...
1 parent 2f4f9e7 commit 968ba81ca5b9b0f45df4d44ebe3c1ca43bc67d91 @bearded bearded committed Mar 21, 2012
Showing with 51 additions and 51 deletions.
  1. +1 −1 README.markdown
  2. +1 −1 lib/babushka/dep_pool.rb
  3. +2 −2 lib/babushka/resource.rb
  4. +2 −2 lib/fancypath/fancypath.rb
  5. +14 −14 lib/inkan/inkan.rb
  6. +31 −31 spec/inkan/inkan_spec.rb
View
@@ -104,7 +104,7 @@ For example, Babushka ships with a meta dep that knows how to install TextMate b
meta :tmbundle, :for => :osx do
accepts_value_for :source
-
+
template {
requires 'TextMate.app'
def path
View
@@ -9,7 +9,7 @@ def initialize source
def count
@pool.length
end
-
+
def names
@pool.keys
end
View
@@ -59,7 +59,7 @@ def self.detect_type_by_extension path
}
}
end
-
+
def self.detect_type_by_contents path
TYPES.keys.detect {|key|
shell("file '#{path}'")[TYPES[key][:file_match]]
@@ -191,7 +191,7 @@ def mountpoint_for output
output.scan(/\s+(\/Volumes\/[^\n]+)/).flatten.first
end
end
-
+
class Resource
CLASSES = {
:deb => FileResource,
@@ -181,11 +181,11 @@ def select(*args)
Dir["#{self}/#{arg}"].map { |p| self.class.new(p) }
end
end
-
+
def empty?
directory? ? children.size == 0 : self.size == 0
end
-
+
def owner
Etc.getpwuid(File.stat(to_s).uid).name
end
View
@@ -1,6 +1,6 @@
class Inkan
attr_accessor :credit, :comment, :comment_suffix
-
+
def self.legitimate?(filename)
File.open(filename) do |file|
file_content = file.read
@@ -14,43 +14,43 @@ def self.legitimate?(filename)
!seal[/\s#{sha(content || '')}\s*$/].nil?
end
end
-
+
def self.seal(file)
new(file).tap {|inkan| yield inkan }.seal
end
-
+
def self.render
new(nil).tap {|inkan| yield inkan }.render
end
-
+
def self.sha(content)
require 'digest/sha1'
Digest::SHA1.hexdigest(content)
end
-
+
def initialize(file)
@file = file
-
+
# Set Defaults
@credit = 'Generated by Inkan'
@comment = '#'
@comment_suffix = ''
end
-
+
def print(string)
file_content << string
end
-
+
def puts(string)
file_content << string << "\n"
end
-
+
def seal
File.open(@file, 'w') do |f|
f.print render
end
end
-
+
def render
if file_content[/\A#!/]
hashbang, remaining_content = file_content.split("\n", 2)
@@ -59,17 +59,17 @@ def render
"#{render_seal}\n#{file_content}"
end
end
-
+
private
-
+
def render_seal
"#{comment} #{credit}. #{sha} #{comment_suffix}"
end
-
+
def sha
self.class.sha(file_content)
end
-
+
def file_content
@file_content ||= ''
end
View
@@ -63,13 +63,13 @@
end
end
end
-
+
describe '.seal' do
it "should write the file after closing the block" do
Inkan.seal('/tmp/spec.txt') do |inkan|
inkan.print 'foo bar baz'
end
-
+
contents = open('/tmp/spec.txt').read
contents.should match(/foo bar baz$/)
contents.should match(/^# Generated by Inkan/)
@@ -81,49 +81,49 @@
result = Inkan.render do |inkan|
inkan.print 'foo bar baz'
end
-
+
result.should match(/foo bar baz$/)
result.should match(/^# Generated by Inkan/)
end
end
-
+
describe '#seal' do
let(:inkan) { Inkan.new('/tmp/spec.txt') }
-
+
it "writes out the contents of the buffer" do
inkan.print "foo bar baz"
inkan.seal
-
+
open('/tmp/spec.txt').read.should match(/foo bar baz$/)
end
-
+
it "adds the credit line to the top of the file" do
inkan.print "foo bar baz"
inkan.seal
-
+
open('/tmp/spec.txt').read.should match(/^# Generated by Inkan/)
end
-
+
it "adds the SHA to the top of the file" do
inkan.print "foo bar baz"
inkan.seal
-
+
sha = Digest::SHA1.hexdigest("foo bar baz")
-
+
open('/tmp/spec.txt').read.should match(/#{sha}/)
end
end
describe '#render' do
let(:inkan) { Inkan.new(nil) }
-
+
before { shell "rm -f /tmp/spec.txt" }
-
+
it "writes out the contents of the buffer" do
inkan.print "foo bar baz"
inkan.render.should match(/foo bar baz$/)
end
-
+
context "when there is no hashbang" do
before { inkan.print "foo bar baz" }
it "adds the credit line to the top of the output" do
@@ -134,7 +134,7 @@
inkan.render.split("\n").first.should match(/#{sha}/)
end
end
-
+
context "when there is a hashbang" do
before { inkan.print "#!/bin/sh\nfoo bar baz" }
it "leaves the hashbang at the top of the file" do
@@ -148,69 +148,69 @@
inkan.render.split("\n")[1].should match(/#{sha}/)
end
end
-
+
it "doesn't write the file" do
inkan.print "foo bar baz"
inkan.render
File.exists?('/tmp/spec.txt').should be_false
end
end
-
+
describe '#puts' do
let(:inkan) { Inkan.new('/tmp/spec.txt') }
-
+
it "adds an extra new line to the output" do
inkan.puts "foo bar baz"
inkan.seal
-
+
open('/tmp/spec.txt').read.should match(/foo bar baz\n$/)
end
end
-
+
describe '#credit' do
let(:inkan) { Inkan.new('/tmp/spec.txt') }
-
+
it "defaults to 'Generated by Inkan'" do
inkan.credit.should == 'Generated by Inkan'
end
-
+
it "should pass through changes to the file comment" do
inkan.credit = "Pat's Magic Code"
inkan.print "foo bar baz"
inkan.seal
-
+
open('/tmp/spec.txt').read.should match(/^# Pat's Magic Code/)
end
end
-
+
describe '#comment' do
let(:inkan) { Inkan.new('/tmp/spec.txt') }
-
+
it "defaults to a hash symbol" do
inkan.comment.should == '#'
end
-
+
it "should pass through changes to the file credit" do
inkan.comment = "//"
inkan.print "foo bar baz"
inkan.seal
-
+
open('/tmp/spec.txt').read.should match(/^\/\/ Generated by Inkan/)
end
end
-
+
describe '#comment_suffix' do
let(:inkan) { Inkan.new('/tmp/spec.txt') }
-
+
it "defaults to a blank string" do
inkan.comment_suffix.should == ''
end
-
+
it "should pass through changes to the file comment" do
inkan.comment_suffix = "*/"
inkan.print "foo bar baz"
inkan.seal
-
+
open('/tmp/spec.txt').read.should match(/\*\/\n/)
end
end

0 comments on commit 968ba81

Please sign in to comment.