act 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3936088dcf64820eb627fd2a7e4fbe3640dc9782
4
- data.tar.gz: bc4c3220f8e74657df4246d715e63027f3a62313
3
+ metadata.gz: 684ed5ccb021e0950d357fa0157cdb631d1852ad
4
+ data.tar.gz: d1fc364445937bb80789188bb88b6119af63da22
5
5
  SHA512:
6
- metadata.gz: 045fdafee182130af6c785b992b08677b317c66cf03fa9cd561ed8c76e2d7a907d080e0e3dcf5ccac729d7b26c7261832d8a14023d3e557ce711831d9acc5595
7
- data.tar.gz: 237036db380d5e761742c5be30b41daa8a598d6581d47f26370326b072604bcf345f97a77fc21981c22639bd0de2707b8a716166e3cf9690e944e749dc4c05cc
6
+ metadata.gz: 2077bc99056dcbbc185fa82aee2eb87f5bcd744fd9fbe0e5de4ba4653f36bd85b9fca8d92ad471b23ee6c722823e5d0595a045724269fb5de2a122895f938be9
7
+ data.tar.gz: 86b85a404e763e410fb3a3a8c333b150a008fc1b7e822264d18e80c91dca2b885986ee3c715ac5a1d71f423f59547ad3164dd5c7a125c35c28bb1403167634c5
data/.kick ADDED
@@ -0,0 +1,30 @@
1
+ recipe :ruby
2
+
3
+ Kicker::Recipes::Ruby.runner_bin = 'bacon --quiet'
4
+
5
+ process do |files|
6
+ specs = files.take_and_map do |file|
7
+ if file =~ %r{lib/cocoapods-core/(.+?)\.rb$}
8
+ s = Dir.glob("spec/**/#{File.basename(file, '.rb')}_spec.rb")
9
+ s.uniq unless s.empty?
10
+ end
11
+ end
12
+ Kicker::Recipes::Ruby.run_tests(specs)
13
+ end
14
+
15
+ # Have written this so many times, probably should make a recipe out of it.
16
+ process do |files|
17
+ files.each do |file|
18
+ case file
19
+ when 'Gemfile'
20
+ files.delete(file)
21
+ execute 'bundle install'
22
+ end
23
+ end
24
+ end
25
+
26
+ recipe :ignore
27
+ ignore(/.*\/?tags/)
28
+ ignore(/.*\/?\.git/)
29
+ ignore(/^tmp/)
30
+
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ bundler_args: --without debugging
3
+ rvm:
4
+ - 2.0.0
5
+
6
+ install: NOEXEC=skip rake bootstrap
7
+ script: bundle exec rake spec
data/Gemfile CHANGED
@@ -1,4 +1,15 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in act.gemspec
4
3
  gemspec
4
+
5
+ group :development do
6
+ gem "bacon"
7
+ gem "mocha-on-bacon"
8
+ gem 'prettybacon'
9
+ gem 'rubocop'
10
+ end
11
+
12
+ group :debugging do
13
+ gem "kicker"
14
+ end
15
+
data/README.md CHANGED
@@ -1,29 +1,106 @@
1
1
  # Act
2
+ [![Build Status](https://travis-ci.org/irrationalfab/act.svg?branch=master)](https://travis-ci.org/irrationalfab/act)
2
3
 
3
- TODO: Write a gem description
4
+ Allows to act on files from the command line efficiently... `cat` for the twenty first century!
4
5
 
5
- ## Installation
6
+ <img src="http://cl.ly/image/0A2p320r442D/Image%202014-04-04%20at%202.59.18%20pm.png" height="50%" width="50%">
6
7
 
7
- Add this line to your application's Gemfile:
8
+ ### Features
8
9
 
9
- gem 'act'
10
+ - Flexible input handling
11
+ - Support for colon syntax
12
+ - Support for GitHub like URLs
13
+ - Automatic syntax highlighting based on the file extension (via [Pygments](http://pygments.org))
14
+ - Fast enoguht for the task
10
15
 
11
- And then execute:
16
+ ## Installation
12
17
 
13
- $ bundle
18
+ ```console
19
+ $ [sudo] gem install act
20
+ $ [sudo] easy_install Pygments #optional
21
+ ```
14
22
 
15
- Or install it yourself as:
23
+ ## Help needed
16
24
 
17
- $ gem install act
25
+ Follow [@fabiopelosin](https://twitter.com/fabiopelosin) to help me beat [@orta](https://twitter.com/orta) in followers count.
18
26
 
19
27
  ## Usage
20
28
 
21
- TODO: Write usage instructions here
29
+ Print a complete file:
30
+
31
+ ```console
32
+ $ act lib/act/command.rb
33
+
34
+ 0 require 'colored'
35
+ 1 require 'claide'
36
+ 2 require 'active_support/core_ext/string/strip'
37
+ [...]
38
+ ```
39
+
40
+ Print the line 10 with the default context (5 lines):
41
+
42
+ ```console
43
+ $ act lib/act/command.rb:10
44
+
45
+ 5 module Act
46
+ 6 class Command < CLAide::Command
47
+ 7
48
+ 8 self.command = 'act'
49
+ 9 self.description = 'Act the command line tool to act on files'
50
+ 10
51
+ 11 def self.options
52
+ 12 [
53
+ 13 ['--open', "Open the file in $EDITOR instead of printing it"],
54
+ 14 ['--no-line-numbers', "Show output without line numbers"],
55
+ 15 ['--version', 'Show the version of Act'],
56
+
57
+ ```
58
+
59
+ Open in `$EDITOR` the file at the given line:
60
+
61
+ ```console
62
+ $ act lib/act/command.rb:10 --open
63
+ ```
64
+
65
+ Print from line 8 to line 12:
66
+
67
+ ```console
68
+ $ act lib/act/command.rb:8-12
69
+
70
+ 8 self.command = 'act'
71
+ 9 self.description = 'Act the command line tool to act on files'
72
+ 10
73
+ 11 def self.options
74
+ 12 [
75
+
76
+ ```
77
+
78
+ Print from line 10 with 2 lines of context:
79
+
80
+ ```console
81
+ $ act lib/act/command.rb:10+2
82
+
83
+ 8 self.command = 'act'
84
+ 9 self.description = 'Act the command line tool to act on files'
85
+ 10
86
+ 11 def self.options
87
+ 12 [
88
+
89
+ ```
90
+
91
+ Show ./lib/act/command.rb from line 8 to line 9:
92
+
93
+ ```console
94
+ $ act https://github.com/irrationalfab/act/blob/master/lib/act/command.rb\#L8-L9
95
+
96
+ 8 self.command = 'act'
97
+ 9 self.description = 'Act the command line tool to act on files'
98
+
99
+ ```
100
+
101
+ Open `$EDITOR` ./lib/act/command.rb at line 8:
22
102
 
23
- ## Contributing
103
+ ```console
104
+ $ act https://github.com/irrationalfab/act/blob/master/lib/act/command.rb\#L8-L9
105
+ ```
24
106
 
25
- 1. Fork it ( https://github.com/[my-github-username]/act/fork )
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 a new Pull Request
data/Rakefile CHANGED
@@ -1,2 +1,62 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ task :default => :spec
4
+
5
+ Rake::Task[:release].enhance [:spec]
6
+
7
+ # Bootstrap
8
+ #-----------------------------------------------------------------------------#
9
+
10
+ desc 'Initializes your working copy to run the specs'
11
+ task :bootstrap do
12
+ sh "bundle install"
13
+ end
14
+
15
+ # Spec
16
+ #-----------------------------------------------------------------------------#
17
+
18
+ desc 'Run all specs'
19
+ task :spec => 'spec:all'
20
+
21
+ namespace :spec do
22
+ def specs(dir)
23
+ FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
24
+ end
25
+
26
+ desc 'Automatically run specs for updated files'
27
+ task :kick do
28
+ exec 'bundle exec kicker -c'
29
+ end
30
+
31
+ task :all do
32
+ title 'Running Unit Tests'
33
+ sh "bundle exec bacon #{specs('**')}"
34
+
35
+ # title 'Checking code style...'
36
+ # Rake::Task['rubocop'].invoke
37
+ end
38
+ end
39
+
40
+ # Rubocop
41
+ #-----------------------------------------------------------------------------#
42
+
43
+ desc 'Checks code style'
44
+ task :rubocop do
45
+ require 'rubocop'
46
+ cli = Rubocop::CLI.new
47
+ result = cli.run(FileList['lib/**/*.rb'].exclude('lib/cocoapods-core/vendor/**/*').to_a)
48
+ abort('RuboCop failed!') unless result == 0
49
+ end
50
+
51
+ #-----------------------------------------------------------------------------#
52
+
53
+ def title(title)
54
+ cyan_title = "\033[0;36m#{title}\033[0m"
55
+ puts
56
+ puts '-' * 80
57
+ puts cyan_title
58
+ puts '-' * 80
59
+ puts
60
+ end
61
+
2
62
 
@@ -8,9 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Act::VERSION
9
9
  spec.authors = ["Fabio Pelosin"]
10
10
  spec.email = ["fabiopelosin@gmail.com"]
11
- spec.summary = %q{Act the command line tool to act on files}
12
- # spec.description = %q{TODO: Write a longer description. Optional.}
13
- spec.homepage = ""
11
+ spec.summary = %q{Act the command line tool to act on files.}
12
+ spec.homepage = "https://github.com/irrationalfab/act"
14
13
  spec.license = "MIT"
15
14
 
16
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -22,6 +21,6 @@ Gem::Specification.new do |spec|
22
21
  spec.add_runtime_dependency "colored", "~> 1.2"
23
22
  spec.add_runtime_dependency "activesupport"
24
23
 
25
- spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "bundler", "~> 1.5"
26
25
  spec.add_development_dependency "rake"
27
26
  end
data/bin/act CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  if $PROGRAM_NAME == __FILE__ && !ENV['COCOAPODS_NO_BUNDLER']
4
4
  ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
5
- require "rubygems"
6
- require "bundler/setup"
5
+ require 'rubygems'
6
+ require 'bundler/setup'
7
7
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
8
8
  end
9
9
 
10
-
11
10
  require 'act'
12
11
  Act::Command.run(ARGV)
data/lib/act.rb CHANGED
@@ -1,6 +1,9 @@
1
- require "act/version"
2
1
 
3
2
  module Act
4
- require 'act/helper'
3
+ require 'act/version'
4
+ require 'act/argument_parser'
5
5
  require 'act/command'
6
+ require 'act/helper'
7
+ require 'act/user_interface'
8
+ require 'pathname'
6
9
  end
@@ -0,0 +1,64 @@
1
+ module Act
2
+ module ArgumentParser
3
+ FileInformation = Struct.new(:path, :from_line, :to_line, :highlight_line)
4
+
5
+ # @return [FileInformation]
6
+ #
7
+ def self.parse_file_information(file, context_lines = nil)
8
+ if file && file != ''
9
+ if file =~ /:/
10
+ components = file.split(':')
11
+ path = components[0]
12
+ line = components[1]
13
+
14
+ if line
15
+ if line =~ /^\d+$/
16
+ highlight_line = line.to_i
17
+ from_line = highlight_line - context_lines
18
+ to_line = highlight_line + context_lines
19
+ elsif line =~ /^\d+-\d+$/
20
+ line_components = line.split('-')
21
+ from_line = line_components[0].to_i
22
+ to_line = line_components[1].to_i
23
+ elsif line =~ /^\d+\+\d+$/
24
+ line_components = line.split('+')
25
+ highlight_line = line_components[0].to_i
26
+ context = line_components[1].to_i
27
+ from_line = highlight_line - context
28
+ to_line = highlight_line + context
29
+ else
30
+ UI.warn 'Unable to parse line data'
31
+ end
32
+ end
33
+ elsif file =~ /#/
34
+ components = file.split('#')
35
+ path = components[0]
36
+ line = components[1]
37
+
38
+ if line
39
+ if line =~ /^L\d+$/
40
+ highlight_line = line[1..-1].to_i
41
+ from_line = highlight_line - context_lines
42
+ to_line = highlight_line + context_lines
43
+ elsif line =~ /^L\d+-L\d+$/
44
+ line_components = line.split('-')
45
+ from_line = line_components[0][1..-1].to_i
46
+ to_line = line_components[1][1..-1].to_i
47
+ else
48
+ UI.warn 'Unable to parse line data'
49
+ end
50
+ end
51
+ else
52
+ path = file
53
+ end
54
+
55
+ result = FileInformation.new
56
+ result.path = path
57
+ result.from_line = from_line
58
+ result.to_line = to_line
59
+ result.highlight_line = highlight_line
60
+ result
61
+ end
62
+ end
63
+ end
64
+ end
@@ -4,14 +4,13 @@ require 'active_support/core_ext/string/strip'
4
4
 
5
5
  module Act
6
6
  class Command < CLAide::Command
7
-
8
7
  self.command = 'act'
9
8
  self.description = 'Act the command line tool to act on files'
10
9
 
11
10
  def self.options
12
11
  [
13
- ['--open', "Open the file in $EDITOR instead of printing it"],
14
- ['--no-line-numbers', "Show output without line numbers"],
12
+ ['--open', 'Open the file in $EDITOR instead of printing it'],
13
+ ['--no-line-numbers', 'Show output without line numbers'],
15
14
  ['--version', 'Show the version of Act'],
16
15
  ].concat(super)
17
16
  end
@@ -19,7 +18,7 @@ module Act
19
18
  def self.run(argv)
20
19
  argv = CLAide::ARGV.new(argv)
21
20
  if argv.flag?('version')
22
- puts VERSION
21
+ UI.puts VERSION
23
22
  exit 0
24
23
  end
25
24
  super(argv)
@@ -28,47 +27,83 @@ module Act
28
27
  def initialize(argv)
29
28
  @open = argv.flag?('open')
30
29
  @number_lines = argv.flag?('line-numbers', true)
31
- @file = argv.shift_argument
30
+ @file_string = argv.shift_argument
32
31
  super
33
32
  end
34
33
 
35
34
  def validate!
36
35
  super
37
- help! "A file is required." unless @file
36
+ help! 'A file is required.' unless @file_string
38
37
  end
39
38
 
39
+ CONTEXT_LINES = 5
40
+
40
41
  def run
41
- file_information = @file.split(':')
42
- path = file_information[0]
43
- line = file_information[1]
44
- context_lines = 5
42
+ clean_file_string = pre_process_file_string(@file_string)
43
+ file = ArgumentParser.parse_file_information(clean_file_string, CONTEXT_LINES)
45
44
 
46
- if @open
47
- command = Helper.open_in_editor_command(path, line)
48
- system(command)
49
- else
50
- string = File.read(path) if File.exists?(path)
45
+ path_exists = File.exist?(file.path)
46
+ unless path_exists
47
+ inferred = infer_local_path(file.path)
48
+ file.path = inferred
49
+ path_exists = true if inferred
50
+ end
51
51
 
52
- if string
53
- if line
54
- line = line.to_i
55
- start_line = Helper.start_line(string, line, context_lines)
56
- end_line = Helper.end_line(string, line, context_lines)
57
- string = Helper.select_lines(string, start_line, end_line)
58
- puts "Showing from line #{start_line} to #{end_line}"
59
- end
52
+ if path_exists
53
+ if @open
54
+ open_file(file)
55
+ else
56
+ cat_file(file)
57
+ end
58
+ else
59
+ UI.warn '[!] File not found'
60
+ end
61
+ end
60
62
 
61
- string = Helper.strip_indentation(string)
62
- string = Helper.syntax_highlith(string, path) if self.ansi_output?
63
- string = Helper.add_line_numbers(string, start_line, line) if @number_lines
63
+ # @return [String]
64
+ #
65
+ def pre_process_file_string(string)
66
+ string.sub(/https?:\/\//, '')
67
+ end
64
68
 
65
- puts
66
- puts string
67
- else
68
- puts "[!] File not found"
69
+ # @return [String, Nil]
70
+ #
71
+ def infer_local_path(path)
72
+ path_components = Pathname(path).each_filename.to_a
73
+ until path_components.empty?
74
+ path_components.shift
75
+ candidate = File.join(path_components)
76
+ if File.exist?(candidate)
77
+ return candidate
69
78
  end
70
79
  end
71
80
  end
72
81
 
82
+ # @return [void]
83
+ #
84
+ def open_file(file)
85
+ line = file.highlight_line || file.from_line
86
+ command = Helper.open_in_editor_command(file.path, line)
87
+ UI.puts command if self.verbose?
88
+ system(command)
89
+ end
90
+
91
+ # @return [void]
92
+ #
93
+ def cat_file(file)
94
+ string = File.read(file.path)
95
+ if file.from_line && file.to_line
96
+ string = Helper.select_lines(string, file.from_line, file.to_line)
97
+ end
98
+
99
+ if string
100
+ string = Helper.strip_indentation(string)
101
+ string = Helper.syntax_highlith(string, file.path) if self.ansi_output?
102
+ string = Helper.add_line_numbers(string, file.from_line, file.highlight_line) if @number_lines
103
+ UI.puts "\n#{string}"
104
+ else
105
+ UI.warn '[!] Nothing to show'
106
+ end
107
+ end
73
108
  end
74
109
  end
@@ -4,7 +4,6 @@ require 'open3'
4
4
 
5
5
  module Act
6
6
  module Helper
7
-
8
7
  # @return [String]
9
8
  #
10
9
  def self.open_in_editor_command(path, line)
@@ -31,10 +30,15 @@ module Act
31
30
  end_line = line + context_lines - 1
32
31
  end
33
32
 
34
- # @return [String]
33
+ # @return [String, Nil]
35
34
  #
36
35
  def self.select_lines(string, start_line, end_line)
37
- string.lines[start_line..end_line].join
36
+ start_line = start_line - 1
37
+ end_line = end_line - 1
38
+ start_line = 0 if start_line < 0
39
+ end_line = 0 if end_line < 0
40
+ components = string.lines[start_line..end_line]
41
+ components.join if components && !components.empty?
38
42
  end
39
43
 
40
44
  # @return [String]
@@ -46,13 +50,14 @@ module Act
46
50
  # @return [String]
47
51
  #
48
52
  def self.add_line_numbers(string, start_line, highlight_line = nil)
53
+ start_line ||= 0
49
54
  line_count = start_line
50
55
  numbered_lines = string.lines.map do |line|
51
- line_count += 1
52
56
  number = line_count.to_s.ljust(3)
53
57
  if highlight_line && highlight_line == line_count
54
58
  number = number.yellow
55
59
  end
60
+ line_count += 1
56
61
  "#{number} #{line}"
57
62
  end
58
63
  numbered_lines.join
@@ -73,4 +78,3 @@ module Act
73
78
  end
74
79
  end
75
80
  end
76
-
@@ -0,0 +1,15 @@
1
+ module Act
2
+ # Manages the UI output.
3
+ #
4
+ module UserInterface
5
+ def self.puts(message)
6
+ STDOUT.puts message
7
+ end
8
+
9
+ def self.warn(message)
10
+ STDERR.puts message
11
+ end
12
+ end
13
+
14
+ UI = UserInterface
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Act
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,94 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Act
4
+ describe ArgumentParser do
5
+
6
+ before do
7
+ @subject = ArgumentParser
8
+ end
9
+
10
+ #-------------------------------------------------------------------------#
11
+
12
+ describe 'parse_file_information' do
13
+
14
+ it 'handles paths' do
15
+ file = 'lib/act/command.rb'
16
+ context_lines = 5
17
+ result = @subject.parse_file_information(file)
18
+ result.path.should == 'lib/act/command.rb'
19
+ result.from_line.should.be.nil
20
+ result.to_line.should.be.nil
21
+ result.highlight_line.should.be.nil
22
+ end
23
+
24
+ it 'returns nil if no file information has been provided' do
25
+ file = nil
26
+ result = @subject.parse_file_information(file)
27
+ result.should.be.nil
28
+ end
29
+
30
+ it 'handles paths where the line number is specified by a colon' do
31
+ file = 'lib/act/command.rb:10'
32
+ context_lines = 5
33
+ result = @subject.parse_file_information(file, context_lines)
34
+ result.path.should == 'lib/act/command.rb'
35
+ result.from_line.should == 5
36
+ result.to_line.should == 15
37
+ result.highlight_line.should == 10
38
+ end
39
+
40
+ it 'handles paths which include the column number' do
41
+ file = 'lib/act/command.rb:10:2'
42
+ context_lines = 5
43
+ result = @subject.parse_file_information(file, context_lines)
44
+ result.path.should == 'lib/act/command.rb'
45
+ result.from_line.should == 5
46
+ result.to_line.should == 15
47
+ result.highlight_line.should == 10
48
+ end
49
+
50
+ it 'handles line ranges' do
51
+ file = 'lib/act/command.rb:10-12'
52
+ context_lines = 5
53
+ result = @subject.parse_file_information(file, context_lines)
54
+ result.path.should == 'lib/act/command.rb'
55
+ result.from_line.should == 10
56
+ result.to_line.should == 12
57
+ result.highlight_line.should.be.nil
58
+ end
59
+
60
+ it 'handles the specification of a custom context' do
61
+ file = 'lib/act/command.rb:10+2'
62
+ context_lines = 5
63
+ result = @subject.parse_file_information(file, context_lines)
64
+ result.path.should == 'lib/act/command.rb'
65
+ result.from_line.should == 8
66
+ result.to_line.should == 12
67
+ result.highlight_line.should == 10
68
+ end
69
+
70
+ it 'supports GitHub style line specification' do
71
+ file = 'lib/act/command.rb#L10'
72
+ context_lines = 5
73
+ result = @subject.parse_file_information(file, context_lines)
74
+ result.path.should == 'lib/act/command.rb'
75
+ result.from_line.should == 5
76
+ result.to_line.should == 15
77
+ result.highlight_line.should == 10
78
+ end
79
+
80
+ it 'supports GitHub style line specification' do
81
+ file = 'lib/act/command.rb#L10-L12'
82
+ result = @subject.parse_file_information(file)
83
+ result.path.should == 'lib/act/command.rb'
84
+ result.from_line.should == 10
85
+ result.to_line.should == 12
86
+ result.highlight_line.should.be.nil
87
+ end
88
+
89
+ end
90
+
91
+ #-------------------------------------------------------------------------#
92
+
93
+ end
94
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Act
4
+ describe Command do
5
+ describe 'In general' do
6
+ it 'runs without exceptions' do
7
+ argv = [__FILE__]
8
+ should.not.raise do
9
+ Act::Command.run(argv)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Act
4
+ describe Helper do
5
+
6
+ before do
7
+ @subject = Helper
8
+ end
9
+
10
+ #-------------------------------------------------------------------------#
11
+
12
+ describe 'select_lines' do
13
+
14
+ it 'returns the lines corresponding to the given range' do
15
+ string = "1\n2\n3\n4"
16
+ result = @subject.select_lines(string, 1, 2)
17
+ result.should == "1\n2\n"
18
+ end
19
+
20
+ it 'use a one-based index' do
21
+ string = "index\nanother"
22
+ result = @subject.select_lines(string, 1, 1)
23
+ result.should == "index\n"
24
+ end
25
+
26
+ it 'returns nil if the range is malformed' do
27
+ string = "1\n2\n3\n4"
28
+ result = @subject.select_lines(string, 2, 1)
29
+ result.should.nil
30
+ end
31
+
32
+ it 'returns nil if the range is outside the lines of the string' do
33
+ string = "1\n2\n3\n4"
34
+ result = @subject.select_lines(string, 10, 11)
35
+ result.should.nil
36
+ end
37
+
38
+ it 'returns the matched part if the range is partially outside the lines of the string' do
39
+ string = "1\n2\n3\n4"
40
+ result = @subject.select_lines(string, 3, 10)
41
+ result.should == "3\n4"
42
+ end
43
+
44
+ it 'handles negative line numbers' do
45
+ string = "1\n2\n3\n4"
46
+ result = @subject.select_lines(string, -2, 2)
47
+ result.should == "1\n2\n"
48
+ end
49
+
50
+ end
51
+
52
+ #-------------------------------------------------------------------------#
53
+
54
+ end
55
+ end
@@ -0,0 +1,36 @@
1
+ # Set up
2
+ #-----------------------------------------------------------------------------#
3
+
4
+ require 'pathname'
5
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
6
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
7
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
8
+
9
+ require 'bundler/setup'
10
+ require 'bacon'
11
+ require 'mocha-on-bacon'
12
+ require 'pretty_bacon'
13
+ require 'act'
14
+
15
+ # Silence the output
16
+ #--------------------------------------#
17
+
18
+ module Act
19
+ module UI
20
+ @output = ''
21
+ @warnings = ''
22
+
23
+ class << self
24
+ attr_accessor :output
25
+ attr_accessor :warnings
26
+ end
27
+
28
+ def self.puts(message)
29
+ @output << message
30
+ end
31
+
32
+ def self.warn(message)
33
+ @warnings << message
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: act
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Pelosin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-03 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.6'
61
+ version: '1.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.6'
68
+ version: '1.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +89,8 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
+ - ".kick"
93
+ - ".travis.yml"
92
94
  - Gemfile
93
95
  - LICENSE.txt
94
96
  - README.md
@@ -96,10 +98,16 @@ files:
96
98
  - act.gemspec
97
99
  - bin/act
98
100
  - lib/act.rb
101
+ - lib/act/argument_parser.rb
99
102
  - lib/act/command.rb
100
103
  - lib/act/helper.rb
104
+ - lib/act/user_interface.rb
101
105
  - lib/act/version.rb
102
- homepage: ''
106
+ - spec/argument_parser_spec.rb
107
+ - spec/command_spec.rb
108
+ - spec/helper_spec.rb
109
+ - spec/spec_helper.rb
110
+ homepage: https://github.com/irrationalfab/act
103
111
  licenses:
104
112
  - MIT
105
113
  metadata: {}
@@ -122,6 +130,10 @@ rubyforge_project:
122
130
  rubygems_version: 2.2.2
123
131
  signing_key:
124
132
  specification_version: 4
125
- summary: Act the command line tool to act on files
126
- test_files: []
133
+ summary: Act the command line tool to act on files.
134
+ test_files:
135
+ - spec/argument_parser_spec.rb
136
+ - spec/command_spec.rb
137
+ - spec/helper_spec.rb
138
+ - spec/spec_helper.rb
127
139
  has_rdoc: