Skip to content

Commit

Permalink
Better README DRY tools
Browse files Browse the repository at this point in the history
  • Loading branch information
rking authored and rking@sharpsaw.org committed Jan 7, 2013
1 parent f5eb59b commit 6eabba0
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
@@ -1 +1,4 @@
source :rubygems; gemspec source :rubygems; gemspec
group :development do
gem 'working', path: '.'
end
2 changes: 2 additions & 0 deletions Guardfile
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'working/guard'
# vim ft=ruby
15 changes: 9 additions & 6 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,22 +1,25 @@
# Working = Working


Whoa!! ☈king's opinionated rig for Ruby dev. Whoa!! ☈king's opinionated rig for Ruby dev.


- Guard for test running (`bundle exec guard`) == Basic Idea

- Opinionatedly uses MiniTest for everything. It makes better in-memory structures than RSpec, and is therefore better for the goals of https://github.com/pry/pry/wiki/pry-de
- 1:1 mapping between stuff in `lib/` or `app/` and the `test/` dirs. - 1:1 mapping between stuff in `lib/` or `app/` and the `test/` dirs.
- Guard for test running (`bundle exec guard`)
- Spork in effect for faster runs - Spork in effect for faster runs


# See also: == See also:


http://github.com/rking/working-rails http://github.com/rking/working-rails


## Example uses: == Example uses:


- https://github.com/rking/demo-ruby-tests - https://github.com/rking/demo-ruby-tests
- https://github.com/rking/monkeynote - https://github.com/rking/monkeynote
- https://github.com/rking/terminal-info - https://github.com/rking/terminal-info


## Installation == Installation


Add this line to your application's Gemfile: Add this line to your application's Gemfile:


Expand All @@ -27,6 +30,6 @@ And then execute:
bundle bundle
working-init # this tinkers with several files (verbosely) working-init # this tinkers with several files (verbosely)


## TODO == TODO


Explain the parts. Explain the parts.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Original file line Diff line number Diff line change
@@ -1 +1,2 @@
require 'bundler/gem_tasks' require 'bundler/gem_tasks'
require 'working/rake_tasks'
1 change: 0 additions & 1 deletion bin/working-init
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ end
'# vim ft=ruby', '# vim ft=ruby',
], ],
'Rakefile' => [ 'Rakefile' => [
# gem TODO require 'bundler/gem_tasks'
%{require 'working/rake_tasks'} %{require 'working/rake_tasks'}
], ],
'test/test_helper.rb' => [ 'test/test_helper.rb' => [
Expand Down
26 changes: 24 additions & 2 deletions lib/working.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,27 @@
require "working/version" require 'working/version'


module Working module Working
# Your code goes here... README_PATH = 'README.rdoc'

class << self
def file_snippet path, start_pattern, end_pattern
desired = []
File.readlines(path).each do |e|
return desired.join if e[end_pattern]
in_desired_region = true if e[start_pattern]
desired << e if in_desired_region
end
desired
end
def readme_snippet start_pattern, end_pattern
file_snippet README_PATH, start_pattern, end_pattern
end

def file_third_line path
File.readlines(path)[2]
end
def third_line_of_readme
file_third_line README_PATH
end
end
end end
1 change: 1 addition & 0 deletions lib/working/rake_tasks.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'bundler/gem_tasks'
task default: :test task default: :test
task :test do task :test do
Dir['test/**/*_test.rb'].each{|e| load e} Dir['test/**/*_test.rb'].each{|e| load e}
Expand Down
2 changes: 1 addition & 1 deletion lib/working/version.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,3 @@
module Working module Working
VERSION = '0.0.7' VERSION = '0.0.8'
end end
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'working/test_helper'
# Spork.prefork doesn't like when this is missing
Spork.each_run do
require 'working'
end
12 changes: 12 additions & 0 deletions test/working_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,12 @@
require './test/test_helper.rb'
class WorkingTest < MiniTest::Unit::TestCase
def test_file_snippet
actual = Working.file_snippet(__FILE__, /^require/, /^class/)
assert_equal "require './test/test_helper.rb'\n", actual
end

# This is because I put the gem.summary on the 3rd line of the README.rdoc
def test_third_line
assert_equal " def test_file_snippet\n", Working.file_third_line(__FILE__)
end
end

0 comments on commit 6eabba0

Please sign in to comment.