areilly_test_gem 0.0.8 → 0.1.7

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.
data/bin/test_gem CHANGED
@@ -1,21 +1,45 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
3
 
4
- require 'test_gem/hello.rb'
5
- require 'test_gem/my_file.rb'
6
- require 'test_gem/test_gem'
7
- require 'test_gem/version.rb'
4
+
5
+ require 'my_file.rb'
6
+ require 'test_gem'
7
+ require 'version.rb'
8
+ require 'exception.rb'
8
9
 
9
10
  include TestGem
10
- puts "\n"
11
- puts 'usage: test_gem <filename> [ first | (last) ]' unless ARGV[0]
12
11
 
13
- file = ARGV[0]
12
+ begin
13
+
14
+ case ARGV[0]
15
+
16
+ when'--init'
17
+ TestGem::init_config
14
18
 
15
- if ARGV[0] && (ARGV[1] == nil) then puts MyFile.first( file ) end
19
+ when nil
20
+ if File.exist?('default_file.txt')
21
+ TestGem::load_config
22
+ config = TestGem::configure
23
+ puts "\n#{config.to_yaml}\n\n"
24
+ else
25
+ raise(MissingConfig, 'No config file, run test_gem with --init')
26
+ end
16
27
 
17
- puts MyFile.first( file ) if ARGV[1] == 'first'
28
+ when '-f', '-l'
29
+ file = ARGV[1] || (raise MissingParam, 'please specify a file name')
30
+ puts MyFile.first( file ) if ARGV[0] == '-f'
31
+ puts MyFile.last(file) if ARGV[0] == '-l'
32
+ puts "\n"
18
33
 
19
- puts MyFile.last(file) if ARGV[1] == 'last'
34
+ when '--delete'
35
+ File.delete('default_file.txt')
20
36
 
21
- puts "\n"
37
+ else
38
+ x = YAML.load(File.open('options.yaml'))
39
+ puts "\n\n Usage for test_gem: test_gem [option] <file name>\n "
40
+ x['test_gem options:'].each {|key, value| puts "#{key} #{value}\n"}
41
+ puts "\n\n"
42
+ end
43
+ rescue => ex
44
+ puts "#{ex.class}: #{ex.message}"
45
+ end
data/lib/exception.rb ADDED
@@ -0,0 +1,10 @@
1
+ module TestGem
2
+
3
+ class MissingConfig < StandardError
4
+ end
5
+
6
+ class MissingParam < StandardError
7
+
8
+ end
9
+
10
+ end
File without changes
data/lib/my_file.rb ADDED
@@ -0,0 +1,43 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'yaml'
4
+
5
+ module TestGem
6
+
7
+ def init_config
8
+ File.open('default_file.txt', 'w'){|file| YAML.dump({ 'default_file_name' => 'default_file.txt', 'supported_types' => %w(txt pdf)}, file)}
9
+ end
10
+
11
+ def load_config(file = 'default_file.txt')
12
+
13
+ begin
14
+ config = File.open(file, 'r'){|loaded_file| YAML.load(loaded_file)}
15
+
16
+ rescue ArgumentError => e
17
+ puts "Could not parse YAML: #{e.message}"
18
+ end
19
+ end
20
+
21
+ def configure
22
+ output = load_config
23
+ end
24
+
25
+ class MyFile
26
+ attr_reader :file_path
27
+
28
+ def initialize(file_path)
29
+ @file_path = File.expand_path(file_path)
30
+ end
31
+
32
+ def MyFile.first(path)
33
+ File.open(path) {|file| file.readline}
34
+ end
35
+
36
+ def MyFile.last(path)
37
+ File.open(path) {|file| file.readlines[-1]}
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
data/lib/test_gem.rb ADDED
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'version.rb'
4
+ #require 'test_gem/hello.rb'
5
+ require 'my_file.rb'
6
+
7
+ module TestGem
8
+
9
+ end
@@ -3,6 +3,6 @@ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
3
  module TestGem
4
4
 
5
5
 
6
- VERSION = '0.0.8'
6
+ VERSION = '0.1.7'
7
7
 
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: areilly_test_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,10 +19,11 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - bin/test_gem
22
- - lib/test_gem/test_gem.rb
23
- - lib/test_gem/version.rb
24
- - lib/test_gem/hello.rb
25
- - lib/test_gem/my_file.rb
22
+ - lib/test_gem.rb
23
+ - lib/version.rb
24
+ - lib/hello.rb
25
+ - lib/my_file.rb
26
+ - lib/exception.rb
26
27
  homepage: http://rubygems.org/gems/test_gem
27
28
  licenses: []
28
29
  post_install_message:
@@ -1,23 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
-
3
- module TestGem
4
-
5
- class MyFile
6
- attr_reader :file_path
7
-
8
- def initialize(file_path)
9
- @file_path = File.expand_path(file_path)
10
- end
11
-
12
- def MyFile.first(path)
13
- File.open(path) {|file| file.readline}
14
- end
15
-
16
- def MyFile.last(path)
17
- File.open(path) {|file| file.readlines[-1]}
18
- end
19
-
20
- end
21
-
22
- end
23
-
@@ -1,9 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
-
3
- require 'test_gem/version.rb'
4
- require 'test_gem/hello.rb'
5
- require 'test_gem/my_file.rb'
6
-
7
- module TestGem
8
-
9
- end