petes_test_gem 0.0.3 → 0.0.6.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.rspec +2 -2
- data/Gemfile +14 -4
- data/Guardfile +0 -1
- data/README.md +42 -29
- data/bin/testgem +66 -0
- data/lib/test_gem/my_error.rb +9 -0
- data/lib/test_gem/my_file.rb +5 -13
- data/lib/test_gem/version.rb +1 -1
- data/lib/test_gem.rb +28 -1
- data/spec/my_error_spec.rb +11 -0
- data/spec/my_file_spec.rb +17 -0
- data/spec/spec_helper.rb +1 -1
- data/{bin → spec}/test.text +0 -0
- data/spec/test_gem_spec.rb +14 -10
- data/test_gem.gemspec +11 -11
- metadata +19 -19
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzJkZTEwN2UyNTY3ZDc3OWRkMzhjZWQ0MmQxMjgwMzNlNjM5ZTA3Yw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWRhNTJkMDhiNjdiZGY2Mjg5MzBiMmE4OWZmYWU5NWVhNzE0NWY3Nw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODg4YjhjMjk1MjkzOWFhNmM3MzY3ZTc1MjgxMmQ1OTQ1ZGYzZmIwMjM2NzM5
|
10
|
+
NTFjNTZjMTM5M2MyYTg1YTRmZTMyM2I4YzIyMjk5ZDY1Nzc3ZmZkOWYyZjM5
|
11
|
+
YWEwZjUyY2ZkOWM3NzE2OTdiYjdiYzdlMTY0NjkwYzc3MzYwMDk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZTU1OGU0YzRjY2FkNDA3ODNiMjUwMDc5Y2RlZGExY2U4YzkxZDEzZmRkODli
|
14
|
+
ZDI2NTQ3MGMxMjliZjc4OWZlNGJjMzZlYmUzMjllMTExOTM1MWUzNjlhMTIx
|
15
|
+
NzM4OWNjYWE3Mjg5M2U5ODA1NzVkMDI4NzNmMzdhN2RkN2JhNTQ=
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
-f d
|
2
|
+
-c
|
data/Gemfile
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in test_gem.gemspec
|
4
|
-
gemspec
|
6
|
+
#gemspec
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
|
9
|
+
group :development, :test do
|
10
|
+
gem 'rb-inotify', '~> 0.8.8'
|
8
11
|
gem 'guard-rspec'
|
9
|
-
gem '
|
12
|
+
gem 'guard'
|
13
|
+
gem 'trollop'
|
14
|
+
|
10
15
|
end
|
16
|
+
|
17
|
+
group :production do
|
18
|
+
gem 'trollop'
|
19
|
+
|
20
|
+
end
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,42 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
##
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
gem
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
# Week 6 Homework
|
2
|
+
## Quiz
|
3
|
+
The quiz will posted in Canvas
|
4
|
+
|
5
|
+
## Code
|
6
|
+
|
7
|
+
1. extend your test_gem
|
8
|
+
1. define your own exception class to handle a missing config file
|
9
|
+
1. when the gem's binary is run
|
10
|
+
1. if the parameter '--init' is passed:
|
11
|
+
1. call TestGem::init_config
|
12
|
+
1. write a default config file to current directory
|
13
|
+
1. config file should be YAML
|
14
|
+
1. the config file values should be
|
15
|
+
1. default_file_name = 'default_file.txt'
|
16
|
+
1. supported_types = ['txt', 'pdf']
|
17
|
+
1. if no parameter is passed:
|
18
|
+
1. call TestGem::configure and pass a hash of configuration values
|
19
|
+
1. read in the config file from current directory
|
20
|
+
1. raise the exception you defined if config file is missing
|
21
|
+
1. values from file should be used to set @default_file_name and @supported_types
|
22
|
+
1. rebuild the gem after updating the version
|
23
|
+
1. push it to RubyGems.org
|
24
|
+
|
25
|
+
### Instructions
|
26
|
+
|
27
|
+
# update the course repository
|
28
|
+
cd ruby_core/RubyCoreLanguage2013
|
29
|
+
git pull origin master
|
30
|
+
|
31
|
+
# create a local repository that is a copy of final_project/test_gem
|
32
|
+
# complete the homework
|
33
|
+
# create a github repository for week6 and push your code
|
34
|
+
# submit the assignment by providing the url to the github repository
|
35
|
+
|
36
|
+
## Reading
|
37
|
+
|
38
|
+
### Required
|
39
|
+
|
40
|
+
* The Ruby Programming Language
|
41
|
+
* 5.6 Exceptions and Exception Handling
|
42
|
+
|
data/bin/testgem
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH << "../lib"
|
4
|
+
|
5
|
+
require "trollop"
|
6
|
+
require 'test_gem'
|
7
|
+
|
8
|
+
if ARGV.empty?
|
9
|
+
TestGem.configure
|
10
|
+
|
11
|
+
else
|
12
|
+
|
13
|
+
opts = Trollop::options do
|
14
|
+
banner <<-eos
|
15
|
+
Almost completely useless program that teaches several
|
16
|
+
interesting things, like YAML and error handling. I added
|
17
|
+
"Trollop" for command-line switches. I call it:
|
18
|
+
|
19
|
+
888888888888 88 88 88888888888 ,ad8888ba, 88888888888 88b d88
|
20
|
+
88 88 88 88 d8"' `"8b 88 888b d888
|
21
|
+
88 88 88 88 d8' 88 88`8b d8'88
|
22
|
+
88 88aaaaaaaa88 88aaaaa 88 88aaaaa 88 `8b d8' 88
|
23
|
+
88 88""""""""88 88""""" 88 88888 88""""" 88 `8b d8' 88
|
24
|
+
88 88 88 88 Y8, 88 88 88 `8b d8' 88
|
25
|
+
88 88 88 88 Y8a. .a88 88 88 `888' 88
|
26
|
+
88 88 88 88888888888 `"Y88888P" 88888888888 88 `8' 88
|
27
|
+
|
28
|
+
USAGE:
|
29
|
+
eos
|
30
|
+
|
31
|
+
|
32
|
+
opt :file, "Supply a file, including path, and it will return the first or last line line",
|
33
|
+
:type => String,
|
34
|
+
:short => 'f'
|
35
|
+
|
36
|
+
opt :init, "Initialize a config file",
|
37
|
+
:short => 'i'
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
Trollop::die :file, "must exist" unless File.exist?(opts[:file]) if opts[:file]
|
43
|
+
|
44
|
+
if opts[:file]
|
45
|
+
file = opts[:file]
|
46
|
+
|
47
|
+
puts "first or last?:"
|
48
|
+
resp = gets.downcase.chomp
|
49
|
+
|
50
|
+
case resp
|
51
|
+
when 'first'
|
52
|
+
puts TestGem::MyFile.first file
|
53
|
+
when 'last'
|
54
|
+
puts TestGem::MyFile.last file
|
55
|
+
else
|
56
|
+
raise ArgumentError.new("seriously, 'first' or 'last'")
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
if opts[:init]
|
63
|
+
TestGem.init_config
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/lib/test_gem/my_file.rb
CHANGED
@@ -1,24 +1,16 @@
|
|
1
1
|
module TestGem
|
2
2
|
class MyFile
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(file_name)
|
7
|
-
@file = file_name
|
8
|
-
@lines = File.readlines(@file)
|
9
|
-
end
|
4
|
+
puts "class #{self} is defined"
|
10
5
|
|
6
|
+
def self.first file_name
|
11
7
|
|
12
|
-
|
13
|
-
@lines[0]
|
14
|
-
end
|
8
|
+
(IO.readlines file_name).first
|
15
9
|
|
16
|
-
def last
|
17
|
-
@lines[-1]
|
18
10
|
end
|
19
11
|
|
20
|
-
def
|
21
|
-
|
12
|
+
def self.last file_name
|
13
|
+
(File.readlines file_name).last
|
22
14
|
end
|
23
15
|
|
24
16
|
end
|
data/lib/test_gem/version.rb
CHANGED
data/lib/test_gem.rb
CHANGED
@@ -1,8 +1,35 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'trollop'
|
1
3
|
require "test_gem/version"
|
2
|
-
|
3
4
|
require 'test_gem/my_file'
|
5
|
+
require 'test_gem/my_error'
|
6
|
+
|
4
7
|
|
5
8
|
module TestGem
|
9
|
+
@LOAD_PATH = File.expand_path('~/.config')
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
if File.exists? "#{@LOAD_PATH}/test_gem_config.yml"
|
13
|
+
conf = YAML.load(File.open("#{@LOAD_PATH}/test_gem_config.yml"))
|
14
|
+
else
|
15
|
+
raise TestGem::MyError.new("Please run --init first, you have no config file")
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
@default_file_name = conf[:default_file_name]
|
20
|
+
@supported_types = conf[:supported_types]
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def self.init_config
|
27
|
+
data = { :default_file_name => 'default_file.txt',
|
28
|
+
:supported_types => ['txt', 'pdf'] }.to_yaml
|
29
|
+
|
30
|
+
File.open("#{@LOAD_PATH}/test_gem_config.yml", 'w') { |f| f.write(data) }
|
31
|
+
|
32
|
+
end
|
6
33
|
|
7
34
|
|
8
35
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'test_gem'
|
3
|
+
|
4
|
+
|
5
|
+
describe TestGem::MyFile do
|
6
|
+
|
7
|
+
|
8
|
+
it 'should have a #first method that returns the first line of text of the supplied file' do
|
9
|
+
TestGem::MyFile.first("lib/test.text").should == "this is a test thing\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have a #last method that returns the last line of text of the supplied file' do
|
13
|
+
TestGem::MyFile.last("lib/test.text").should == "and reads the first and last file\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
2
|
require 'test_gem'
|
data/{bin → spec}/test.text
RENAMED
File without changes
|
data/spec/test_gem_spec.rb
CHANGED
@@ -4,23 +4,27 @@ describe TestGem do
|
|
4
4
|
it 'should have a version number' do
|
5
5
|
TestGem::VERSION.should_not be_nil
|
6
6
|
end
|
7
|
+
context "TestGem::init_config" do
|
8
|
+
describe TestGem::init_config do
|
7
9
|
|
10
|
+
it "should be a method" do
|
11
|
+
TestGem.init_config.should be_a Method
|
12
|
+
end
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@test = TestGem::MyFile.new("lib/test.text")
|
14
|
+
it "should write a file to the correct directory" do
|
15
|
+
#TestGem.init_config.shoulf
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
context "TestGem::configure" do
|
21
|
+
describe TestGem.configure do
|
22
|
+
|
19
23
|
|
20
|
-
|
21
|
-
@test.last.should == "and reads the first and last file\n"
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
|
-
end
|
25
27
|
|
28
|
+
end
|
26
29
|
end
|
30
|
+
|
data/test_gem.gemspec
CHANGED
@@ -4,18 +4,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'test_gem/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name
|
8
|
-
gem.version
|
9
|
-
gem.authors
|
10
|
-
gem.email
|
11
|
-
gem.description
|
12
|
-
gem.summary
|
13
|
-
gem.homepage
|
14
|
-
gem.license
|
7
|
+
gem.name = "petes_test_gem"
|
8
|
+
gem.version = TestGem::VERSION
|
9
|
+
gem.authors = ["Peter Bomars"]
|
10
|
+
gem.email = ["pbomars@gmail.com"]
|
11
|
+
gem.description = %q{TestGem for class}
|
12
|
+
gem.summary = %q{Gem for class that reads the first and last line of a file}
|
13
|
+
gem.homepage = "https://github.com/gekken/week5"
|
14
|
+
gem.license = "MIT"
|
15
15
|
|
16
|
-
gem.files
|
17
|
-
gem.executables
|
18
|
-
gem.test_files
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
21
|
gem.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: petes_test_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6.pre
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Peter Bomars
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
11
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,16 +34,15 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
|
-
description:
|
41
|
+
description: TestGem for class
|
47
42
|
email:
|
48
43
|
- pbomars@gmail.com
|
49
44
|
executables:
|
50
|
-
-
|
45
|
+
- testgem
|
51
46
|
extensions: []
|
52
47
|
extra_rdoc_files: []
|
53
48
|
files:
|
@@ -58,40 +53,45 @@ files:
|
|
58
53
|
- LICENSE.txt
|
59
54
|
- README.md
|
60
55
|
- Rakefile
|
61
|
-
- bin/
|
56
|
+
- bin/testgem
|
62
57
|
- lib/test.text
|
63
58
|
- lib/test_gem.rb
|
59
|
+
- lib/test_gem/my_error.rb
|
64
60
|
- lib/test_gem/my_file.rb
|
65
61
|
- lib/test_gem/version.rb
|
62
|
+
- spec/my_error_spec.rb
|
63
|
+
- spec/my_file_spec.rb
|
66
64
|
- spec/spec_helper.rb
|
65
|
+
- spec/test.text
|
67
66
|
- spec/test_gem_spec.rb
|
68
67
|
- test_gem.gemspec
|
69
|
-
homepage:
|
68
|
+
homepage: https://github.com/gekken/week5
|
70
69
|
licenses:
|
71
70
|
- MIT
|
71
|
+
metadata: {}
|
72
72
|
post_install_message:
|
73
73
|
rdoc_options: []
|
74
74
|
require_paths:
|
75
75
|
- lib
|
76
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
77
|
requirements:
|
79
78
|
- - ! '>='
|
80
79
|
- !ruby/object:Gem::Version
|
81
80
|
version: '0'
|
82
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
82
|
requirements:
|
85
|
-
- - ! '
|
83
|
+
- - ! '>'
|
86
84
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
85
|
+
version: 1.3.1
|
88
86
|
requirements: []
|
89
87
|
rubyforge_project:
|
90
|
-
rubygems_version:
|
88
|
+
rubygems_version: 2.0.0.rc.2
|
91
89
|
signing_key:
|
92
|
-
specification_version:
|
93
|
-
summary:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Gem for class that reads the first and last line of a file
|
94
92
|
test_files:
|
93
|
+
- spec/my_error_spec.rb
|
94
|
+
- spec/my_file_spec.rb
|
95
95
|
- spec/spec_helper.rb
|
96
|
+
- spec/test.text
|
96
97
|
- spec/test_gem_spec.rb
|
97
|
-
has_rdoc:
|