petes_test_gem 0.0.3 → 0.0.6.pre

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 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
- --format documentation
2
- --color
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
- group :development do
7
- gem 'guard'
8
+
9
+ group :development, :test do
10
+ gem 'rb-inotify', '~> 0.8.8'
8
11
  gem 'guard-rspec'
9
- gem 'rb-inotify'
12
+ gem 'guard'
13
+ gem 'trollop'
14
+
10
15
  end
16
+
17
+ group :production do
18
+ gem 'trollop'
19
+
20
+ end
data/Guardfile CHANGED
@@ -21,4 +21,3 @@ guard 'rspec' do
21
21
  watch(%r{^spec/acceptance/(.+)\.feature$})
22
22
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
23
  end
24
-
data/README.md CHANGED
@@ -1,29 +1,42 @@
1
- # TestGem
2
-
3
- TODO: Write a gem description
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'test_gem'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install test_gem
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
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 new Pull Request
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
@@ -0,0 +1,9 @@
1
+ module TestGem
2
+
3
+
4
+ class MyError < StandardError
5
+ def initialize(msg="Error unknown, nothing supplied")
6
+ super msg
7
+ end
8
+ end
9
+ end
@@ -1,24 +1,16 @@
1
1
  module TestGem
2
2
  class MyFile
3
3
 
4
- attr_accessor :file, :lines
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
- def first
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 name
21
- @file
12
+ def self.last file_name
13
+ (File.readlines file_name).last
22
14
  end
23
15
 
24
16
  end
@@ -1,3 +1,3 @@
1
1
  module TestGem
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.6.pre"
3
3
  end
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,11 @@
1
+ require "rspec"
2
+ require "spec_helper"
3
+
4
+ describe "MyError" do
5
+
6
+ it "should exist" do
7
+ File.exists?("/test_gem/my_error.rb")
8
+ end
9
+
10
+
11
+ 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('../../lib', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
2
  require 'test_gem'
File without changes
@@ -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
- describe TestGem::MyFile do
10
-
11
- before :each do
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
- it 'should have a #first method that returns the first line of text of the supplied file' do
17
- @test.first.should == "this is a test thing\n"
18
- end
20
+ context "TestGem::configure" do
21
+ describe TestGem.configure do
22
+
19
23
 
20
- it 'should have a #last method that returns the last line of text of the supplied file' do
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 = "petes_test_gem"
8
- gem.version = TestGem::VERSION
9
- gem.authors = ["Peter Bomars"]
10
- gem.email = ["pbomars@gmail.com"]
11
- gem.description = %q{Test gem Week5 Homework}
12
- gem.summary = %q{Simple gem that demonstrates File and Module}
13
- gem.homepage = ""
14
- gem.license = "MIT"
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 = `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)/})
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.3
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 00:00:00.000000000 Z
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: Test gem Week5 Homework
41
+ description: TestGem for class
47
42
  email:
48
43
  - pbomars@gmail.com
49
44
  executables:
50
- - test.text
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/test.text
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: '0'
85
+ version: 1.3.1
88
86
  requirements: []
89
87
  rubyforge_project:
90
- rubygems_version: 1.8.25
88
+ rubygems_version: 2.0.0.rc.2
91
89
  signing_key:
92
- specification_version: 3
93
- summary: Simple gem that demonstrates File and Module
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: