rench 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OWQ3MGZjYzdhMmVkYzRlMDhlZDFkNjkyZTI0MTZiZTFjMDk0ODg2YQ==
5
- data.tar.gz: !binary |-
6
- NmQ0NWMxMjkzNDFlYmE1ZDk3ZTQ5MGU3OWE5NWNhOWRkNzExNWFjYQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NWUyMjNmNzAwNmEyY2Q4ZjhiZjRkNjc0OTllZGM2MmMwNjc2NDUyZmZiM2U1
10
- MWRlNjhjM2Q4MDg2ODdmNzE1NjEzYjQ1MDg5YWE3YjZlZjU5ZmMxOGRhMTIw
11
- OGFmNzQyOGZhYjNiOGEyODU5NTMyYjlmYzJjMWMwNDg0Y2IwMTg=
12
- data.tar.gz: !binary |-
13
- MTM1Y2UzZTUxMmY4ZTRlYjdmM2YyOTFjMDkzNWJkNGI4NmJiZGJiZGUxOWEz
14
- MDQ0YzQzNzA0NDc0MWQzMzE1ZWZmYTM1OGRiMjMyZTcyMzliMDU1YjJmYzJi
15
- ZDJmMzNiZDYyMTI4Mzk4NjAxMTkwYWRjY2RhYmUxNTYyMWIzZTc=
2
+ SHA1:
3
+ metadata.gz: 2dd25c974c390ff8610e73dc999eb168cc98c26c
4
+ data.tar.gz: 9095292dd7794fc6d7ecdd62632d5396728e67f2
5
+ SHA512:
6
+ metadata.gz: 194b16b55f404e3d83aa035a2dbc97a896a8675d1ee0eec6444d6056211d465b6d85632924db3a8701f976c6257cb32ac448e704dcff7d3fbd4976d8b060c622
7
+ data.tar.gz: 17948901ac40b6e6d1396440f619ec465ecb6cda7168855e4a5175c258e68128fc899d5a3d42b1d50784fe06b5fc28a7e5fba981b4c1978856534f5efd0d1b4b
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rench
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p195
data/README.md CHANGED
@@ -1,18 +1,22 @@
1
1
  # Rench
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/mrmicahcooper/rench.png)](https://codeclimate.com/github/mrmicahcooper/rench)
4
+ [![Build Status](https://travis-ci.org/mrmicahcooper/rench.png?branch=master)](https://travis-ci.org/mrmicahcooper/rench)
5
+
3
6
  Do you ever have a list of files you pull from one project to another?
4
- Here is a cooler way to do that:
7
+ Here is a cooler way to do that:
5
8
 
6
- Put them in your 'toolbox' repo, maintain them, share them, and most importantly- retrieve them easily.
9
+ Put them in your 'toolbox' repo, maintain them, share them, and most
10
+ importantly, retrieve them easily.
7
11
 
8
12
  - Make a Github repository called toolbox.
9
13
  - Make a `toolbox/tools` directory
10
- - Fill it with all the files you use have ever used on more than one
14
+ - Fill it with all the files you have ever used on more than one
11
15
  project.
12
- - Make a .markdown file for all these tools so you, and anyone
13
- else, can always know how to use your tools.
14
- - When you're working on a project, grab your tools and stick them where
15
- you need with Rench.
16
+ - Make a .markdown file for all your tools so you, and anyone
17
+ else, know how to use them.
18
+ - When you're working on a project, grab your tools and place them wherever
19
+ needed with Rench.
16
20
 
17
21
  ## Instructions
18
22
 
@@ -24,15 +28,12 @@ $ rench <github_username> <filename> [new_file_location]
24
28
 
25
29
  $ rench mrmicahcooper active_model_spec_helper.rb
26
30
 
27
- #=> Where do you wanna put "active_model_spec_helepr"?
31
+ #=> Where do you wanna put "active_model_spec_helper"?
28
32
 
29
- (blank) #=> saves as: active_model_spec_helepr.rb
30
- or
33
+ (blank) #=> saves as: active_model_spec_helper.rb
31
34
  spec_helper.rb #=> saves as: spec_helper.rb
32
- or
33
- spec/ #=> saves as: spec/active_model_spec_helepr.rb
34
- or
35
- spec #=> saves as: spec/active_model_spec_helepr.rb
35
+ spec/ #=> saves as: spec/active_model_spec_helper.rb
36
+ spec #=> saves as: spec/active_model_spec_helper.rb
36
37
  ```
37
38
 
38
39
  #### Alternatively
@@ -40,8 +41,7 @@ You can just enter a Github user and it will print their tools for you
40
41
  to choose one.
41
42
 
42
43
  ```bash
43
-
44
- $rench mrmicahcooper
44
+ $ rench mrmicahcooper
45
45
 
46
46
  Choose a file:
47
47
  [0] active_record_spec_helper.rb
@@ -61,7 +61,8 @@ Where do you wanna put "ui_controller.rb"?
61
61
 
62
62
  This is great for exploring other people's toolboxes.
63
63
 
64
-
65
64
  ### Dependencies
66
65
 
67
- - curl
66
+ - You're gonna need __[curl][]__ to get this baby turnin'.
67
+
68
+ [curl]: http://en.wikipedia.org/wiki/CURL
data/bin/rench CHANGED
@@ -5,5 +5,4 @@ require 'pathname'
5
5
  $:.unshift Pathname.new(__FILE__).join('../../lib').expand_path.to_s
6
6
  require 'rench'
7
7
 
8
- Rench::CLI.new(*ARGV).download_file
9
-
8
+ Rench::CLI.new(*ARGV).crank
data/lib/rench/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rench
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/rench.rb CHANGED
@@ -1,105 +1,73 @@
1
1
  require "rench/version"
2
+ require "highline"
2
3
  require "faraday"
3
4
  require 'json'
5
+ require 'readline'
4
6
 
5
7
  class Rench::CLI
6
8
 
7
- attr_reader :github_username, :filename, :file_location
8
-
9
- def ask_for_file_location
10
- $stdout.write "Where do you wanna put \"#{filename}\"? "
11
- file = $stdin.gets.to_s.strip
12
- if file == ""
13
- filename
14
- else
15
- file
16
- end
9
+ def crank
10
+ system("curl #{url} -o #{file_location} --create-dirs")
17
11
  end
18
12
 
19
- def ask_for_github_username
20
- $stdout.puts "Please enter a Github username"
21
- $stdin.gets.strip
13
+ def initialize(username = nil, filename = nil, new_file_location = nil)
14
+ @github_username = username
15
+ @filename = filename
16
+ @file_location = new_file_location
22
17
  end
23
18
 
24
- def build_file_location(input)
25
- if input.match /\w+\.\w+/
26
- input
27
- elsif input.match /\/$/
28
- input + filename
29
- elsif input == ""
30
- ""
31
- else
32
- input + "/" + filename
33
- end
19
+ def github_username
20
+ @github_username ||= highline.ask "Enter a Github username"
34
21
  end
35
22
 
36
- def chosen_file
37
- print_renches
38
- chosen_file = $stdin.gets.to_i
39
- toolbox[chosen_file]
23
+ def filename
24
+ @filename ||= highline.choose(tool_menu)
40
25
  end
41
26
 
42
- def download_file
43
- response = Faraday.new.get(url)
44
- if response.status == 200
45
- system("curl #{url} -o #{file_location} --create-dirs")
46
- $stdout.puts "=> #{ file_location }"
47
- else
48
- $stdout.puts "File not found in #{github_username}'s toolbox"
49
- end
27
+ def tool_menu
28
+ toolbox.map{|tool| tool["name"]}
50
29
  end
51
30
 
52
31
  def file_location
53
- build_file_location(@file_location ||= ask_for_file_location)
32
+ @file_location ||= choose_file_location
54
33
  end
55
34
 
56
- def filename
57
- @filename ||= chosen_file
35
+ def choose_file_location
36
+ highline.ask("Where do you want to download the file?", file_options) do |question|
37
+ question.readline = true
38
+ question.answer_type = String
39
+ end
58
40
  end
59
41
 
60
- def github_username
61
- @github_username ||= ask_for_github_username
42
+ def highline
43
+ @highline ||= HighLine.new
62
44
  end
63
45
 
64
- def initialize(username = nil, filename = nil, new_file_location = nil)
65
- @github_username = username
66
- @filename = filename
67
- @file_location = new_file_location
46
+ private
47
+
48
+ def file_options
49
+ Dir.glob("**/*")
68
50
  end
69
51
 
70
- def print_renches
71
- if tools_found?
72
- $stdout.puts "Choose a file:"
73
- toolbox.each_with_index do |tool, i|
74
- $stdout.puts "[#{i}] #{tool}"
52
+ def response
53
+ @response ||= Faraday.new.get(toolbox_url).tap do |resp|
54
+ if resp.status != 200
55
+ highline.say("No toolbox found for #{@github_username}")
56
+ exit
75
57
  end
76
- else
77
- Kernel.abort "No tools found for \"#{github_username}\""
78
58
  end
79
59
  end
80
60
 
81
61
  def toolbox
82
- toolbox_response_body.map{|tool_file| tool_file["name"] }
83
- end
84
-
85
- def toolbox_response
86
- @toolbox_response ||= Faraday.get(toolbox_url)
87
- end
88
-
89
- def tools_found?
90
- toolbox_response.status == 200
62
+ @toolbox ||= JSON.parse(response.body)
91
63
  end
92
64
 
93
- def toolbox_response_body
94
- @toolbox_response_body ||= JSON.parse toolbox_response.body
65
+ def toolbox_url
66
+ "https://api.github.com/repos/#{github_username}/toolbox/contents/tools"
95
67
  end
96
68
 
97
69
  def url
98
70
  "https://raw.github.com/#{github_username}/toolbox/master/tools/#{filename}"
99
71
  end
100
72
 
101
- def toolbox_url
102
- "https://api.github.com/repos/#{github_username}/toolbox/contents/tools"
103
- end
104
-
105
73
  end
data/rench.gemspec CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
5
5
  gem.authors = ["Micah Cooper"]
6
6
  gem.email = ["mrmicahcooper@gmail.com"]
7
7
  gem.description = %q{Keep all the files you use often in a Toolbox. Then easily grab them (or anyones) with Rench. }
8
- gem.summary = "Have a toolbox of often used files. Use them and share them easily."
8
+ gem.summary = "Have a toolbox of often used files. Use and share them easily."
9
9
  gem.homepage = "http://github.com/mrmicahcooper/rench"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
@@ -16,8 +16,10 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Rench::VERSION
17
17
 
18
18
  gem.add_dependency 'faraday'
19
+ gem.add_dependency 'highline'
19
20
 
20
21
  gem.add_development_dependency 'pry'
21
22
  gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'rake'
22
24
 
23
25
  end
data/rench.jpg ADDED
Binary file
@@ -1,138 +1,104 @@
1
1
  require 'rench'
2
2
 
3
3
  describe Rench::CLI do
4
+ let(:rench) { Rench::CLI.new "mrmicahcooper", "file.txt" }
5
+ let(:highline) { rench.highline }
4
6
 
5
- let(:github_user) { "mrmicahcooper" }
7
+ describe "#crank" do
8
+ after{ File.delete 'tmp/thing.rb' }
6
9
 
7
- subject { described_class.new(github_user, 'active_record_spec_helper.rb') }
8
-
9
- describe "#ask_for_github_username" do
10
- before { $stdin.stub(gets: "micah") }
11
- it "asks for a username" do
12
- subject.ask_for_github_username.should == "micah"
10
+ let(:rench) do
11
+ Rench::CLI.new('mrmicahcooper', 'ui_controller.rb', 'tmp/thing.rb')
13
12
  end
14
- end
15
13
 
16
- describe "#build_file_location" do
17
- context "when input ends with a slash" do
18
- it "contactinates the string with the filename" do
19
- subject.build_file_location("app/").should == "app/active_record_spec_helper.rb"
20
- end
21
- end
22
- context "when the input has no file extension" do
23
- it "joins the input and filename with a '/'" do
24
- subject.build_file_location("app").should == "app/active_record_spec_helper.rb"
25
- end
26
- end
27
- context "when the input has a file extension" do
28
- it "returns just the input" do
29
- subject.build_file_location("app.rb").should == "app.rb"
30
- end
14
+ it "downloads the file" do
15
+ rench.crank
16
+ File.read('tmp/thing.rb').should_not == ""
31
17
  end
32
- context "when input is blank" do
33
- it "returns blank" do
34
- subject.build_file_location("").should == ""
35
- end
36
- end
37
- end
38
18
 
39
- describe "#chosen_file" do
40
- before do
41
- subject.stub(toolbox: ["form_builder.rb"])
42
- $stdin.stub(gets: "0")
43
- end
44
- it "returns a a list of tools from that github_user" do
45
- subject.chosen_file.should == "form_builder.rb"
46
- end
47
19
  end
48
20
 
49
- describe "#download_file" do
50
- context "when file is found" do
51
- before { $stdin.stub(gets: "text.txt") }
52
- it "downloads the specified tool file" do
53
- subject.download_file
54
- File.read("text.txt").should be
55
- File.delete("text.txt")
56
- end
57
- end
58
-
59
- context "when file is not found" do
60
- before { $stdin.stub(gets: "text.txt") }
61
- let(:github_user) { "someone_else" }
62
- it "returns message that file was not found" do
63
- $stdout.should_receive(:puts).with("File not found in someone_else's toolbox")
64
- subject.download_file
21
+ describe "#github_username" do
22
+ context "when NOT initialized with a username" do
23
+ let(:rench) { Rench::CLI.new }
24
+ it "prompts for username" do
25
+ highline.should_receive(:ask).with("Enter a Github username")
26
+ rench.github_username
65
27
  end
66
28
  end
67
29
 
68
- context "when choosing a new directory" do
69
- before { $stdin.stub(gets: "app/text.txt") }
70
- it "creates the director(y|ies)" do
71
- subject.download_file
72
- File.read("app/text.txt").should be
73
- FileUtils.rm_r("app/text.txt")
30
+ context "when initialized with a username" do
31
+ it "doesn't prompt for username" do
32
+ highline.should_not_receive(:ask)
33
+ rench.github_username
74
34
  end
75
35
  end
76
36
  end
77
37
 
78
- describe '#new' do
79
- it "knows the github username" do
80
- subject.github_username.should_not be_nil
38
+ describe "#filename" do
39
+ context "when NOT initialized with filename" do
40
+ let(:rench) { Rench::CLI.new "mrmicahcooper" }
41
+ it "asks to choose a file from the tool menu" do
42
+ tools = []
43
+ highline.should_receive(:choose).with(tools)
44
+ rench.should_receive(:tool_menu).and_return(tools)
45
+ rench.filename
46
+ end
81
47
  end
82
- it "knows the filename" do
83
- subject.filename.should_not be_nil
48
+ context "when initialized with filename" do
49
+ it "does not ask to choose a file" do
50
+ highline.should_not_receive(:choose)
51
+ rench.filename
52
+ end
84
53
  end
85
54
  end
86
55
 
87
- describe "#print_renches" do
88
-
89
- context "when toolbox is empty" do
56
+ describe "#tool_menu" do
57
+ context "when there are no tools" do
90
58
  before do
91
- subject.stub(tools_found?: false)
92
- Kernel.stub(:abort)
59
+ response = double(status: 400, body: "")
60
+ Faraday::Connection.any_instance.stub(get: response)
93
61
  end
94
- it "exits with a toolbox not found message" do
95
- Kernel.should_receive(:abort).with("No tools found for \"mrmicahcooper\"")
96
- subject.print_renches
62
+ it "returns a 'no tools' message" do
63
+ highline.should_receive(:say).with("No toolbox found for mrmicahcooper")
64
+ begin
65
+ rench.tool_menu
66
+ rescue SystemExit
67
+ end
97
68
  end
98
69
  end
99
70
 
100
- context "when toolbox is not empty" do
71
+ context "when there are tools" do
101
72
  before do
102
- subject.stub(toolbox: ["file.rb", "file2.rb"])
103
- subject.stub(tools_found?: true)
73
+ response = double(status: 200, body: '[{"name":"tool.txt"}]')
74
+ Faraday::Connection.any_instance.stub(get: response)
104
75
  end
105
- it "prints a list of all the renches with a number next to it" do
106
- $stdout.should_receive(:puts).at_least(3)
107
- subject.print_renches
76
+ it "returns an array of tool names" do
77
+ rench.tool_menu.should == ["tool.txt"]
108
78
  end
109
79
  end
110
-
111
80
  end
112
81
 
113
- describe "#toolbox" do
114
- it "returns a collection of filenames from the github users toolbox repo" do
115
- subject.toolbox.size.should > 2
116
- subject.toolbox.inspect.should match /ui_controller.rb/
117
- end
118
- end
119
-
120
- describe "#tool_found?" do
121
- let(:github_user) { "121ivesnv" }
122
- it "returns false if no toolbox is found" do
123
- subject.tools_found?.should be_false
82
+ describe "#file_location" do
83
+ context "when intialized with a filename" do
84
+ let(:rench) { Rench::CLI.new('mrmichacooper', "", "/location") }
85
+ it "uses the passed in file_location" do
86
+ rench.file_location.should == "/location"
87
+ end
124
88
  end
125
- end
126
-
127
- describe "#toolbox_url" do
128
- it "builds the toolbox_url" do
129
- subject.toolbox_url.should == "https://api.github.com/repos/mrmicahcooper/toolbox/contents/tools"
89
+ context "when NOT initialize with a file location" do
90
+ let(:rench) { Rench::CLI.new('mrmichacooper', "" ) }
91
+ it "asks for a location" do
92
+ rench.should_receive(:choose_file_location)
93
+ rench.file_location
94
+ end
130
95
  end
131
96
  end
132
97
 
133
- describe "#url" do
134
- it "builds the github url" do
135
- subject.url.should == "https://raw.github.com/mrmicahcooper/toolbox/master/tools/active_record_spec_helper.rb"
98
+ describe "#choose_file_location" do
99
+ it "asks where to put the file" do
100
+ rench.highline.should_receive(:ask)
101
+ rench.choose_file_location
136
102
  end
137
103
  end
138
104
 
metadata CHANGED
@@ -1,58 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Cooper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-08 00:00:00.000000000 Z
11
+ date: 2013-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: pry
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ! '>='
45
+ - - '>='
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ! '>='
52
+ - - '>='
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ! '>='
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
46
74
  - !ruby/object:Gem::Version
47
75
  version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - ! '>='
80
+ - - '>='
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
- description: ! 'Keep all the files you use often in a Toolbox. Then easily grab them
83
+ description: 'Keep all the files you use often in a Toolbox. Then easily grab them
56
84
  (or anyones) with Rench. '
57
85
  email:
58
86
  - mrmicahcooper@gmail.com
@@ -63,7 +91,8 @@ extra_rdoc_files: []
63
91
  files:
64
92
  - .gitignore
65
93
  - .rspec
66
- - .rvmrc
94
+ - .ruby-gemset
95
+ - .ruby-version
67
96
  - Gemfile
68
97
  - LICENSE
69
98
  - README.md
@@ -72,6 +101,7 @@ files:
72
101
  - lib/rench.rb
73
102
  - lib/rench/version.rb
74
103
  - rench.gemspec
104
+ - rench.jpg
75
105
  - spec/lib/rench_spec.rb
76
106
  homepage: http://github.com/mrmicahcooper/rench
77
107
  licenses: []
@@ -82,19 +112,19 @@ require_paths:
82
112
  - lib
83
113
  required_ruby_version: !ruby/object:Gem::Requirement
84
114
  requirements:
85
- - - ! '>='
115
+ - - '>='
86
116
  - !ruby/object:Gem::Version
87
117
  version: '0'
88
118
  required_rubygems_version: !ruby/object:Gem::Requirement
89
119
  requirements:
90
- - - ! '>='
120
+ - - '>='
91
121
  - !ruby/object:Gem::Version
92
122
  version: '0'
93
123
  requirements: []
94
124
  rubyforge_project:
95
- rubygems_version: 2.0.2
125
+ rubygems_version: 2.0.3
96
126
  signing_key:
97
127
  specification_version: 4
98
- summary: Have a toolbox of often used files. Use them and share them easily.
128
+ summary: Have a toolbox of often used files. Use and share them easily.
99
129
  test_files:
100
130
  - spec/lib/rench_spec.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm gemset use ruby-1.9.3-p327@rench --create