smilodon 0.2.7 → 0.2.8
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/VERSION +1 -1
- data/lib/smilodon/fakes.rb +10 -0
- data/lib/smilodon.rb +15 -8
- data/smilodon.gemspec +5 -3
- data/spec/lib/smilodon_spec.rb +6 -0
- data/spec/test_files/bar.csv +0 -0
- data/spec/test_files/foo.csv +0 -0
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.8
|
data/lib/smilodon/fakes.rb
CHANGED
@@ -37,3 +37,13 @@ module FakePopulatorWithMultipleFiles
|
|
37
37
|
# Populate the test file.
|
38
38
|
populates 'TestFile1', 'TestFile2', 'TestFile3', :directory => 'db/populate/files'
|
39
39
|
end
|
40
|
+
|
41
|
+
# A fake populator module with overridden directory for testing.
|
42
|
+
module FakePopulatorWithOnlyDirectory
|
43
|
+
|
44
|
+
# Extend it with the Populator module.
|
45
|
+
extend Smilodon::Populator
|
46
|
+
|
47
|
+
# Populate the test file.
|
48
|
+
populates :directory => 'spec/test_files'
|
49
|
+
end
|
data/lib/smilodon.rb
CHANGED
@@ -47,11 +47,16 @@ module Smilodon
|
|
47
47
|
|
48
48
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
49
49
|
|
50
|
-
|
51
|
-
self.directory =
|
50
|
+
|
51
|
+
self.directory = if defined?(Rails)
|
52
|
+
"#{Rails.root}/#{options[:directory] || DIRECTORY}"
|
53
|
+
else
|
54
|
+
options[:directory] || DIRECTORY
|
55
|
+
end
|
52
56
|
self.type = options[:type] || TYPE
|
53
57
|
self.header = options[:header]
|
54
58
|
self.before = options[:before]
|
59
|
+
self.files = args.empty? ? grab_files : args
|
55
60
|
end
|
56
61
|
|
57
62
|
# Parses the data file content and processes each row.
|
@@ -87,7 +92,13 @@ module Smilodon
|
|
87
92
|
end
|
88
93
|
|
89
94
|
private
|
90
|
-
|
95
|
+
|
96
|
+
def grab_files
|
97
|
+
Dir.glob("#{directory}/*").map do |file|
|
98
|
+
File.basename(file, File.extname(file))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
91
102
|
# The parser to use based on the type of data file.
|
92
103
|
#
|
93
104
|
# @param [String] Name of file to be read
|
@@ -103,11 +114,7 @@ module Smilodon
|
|
103
114
|
#
|
104
115
|
# @return [String] The absolute path.
|
105
116
|
def path(file)
|
106
|
-
|
107
|
-
"#{Rails.root}/#{directory}/#{file}.#{type}"
|
108
|
-
else
|
109
|
-
"#{directory}/#{file}.#{type}"
|
110
|
-
end
|
117
|
+
"#{directory}/#{file}.#{type}"
|
111
118
|
end
|
112
119
|
|
113
120
|
# Reads the data file.
|
data/smilodon.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{smilodon}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Umang Chouhan"]
|
12
|
-
s.date = %q{2012-02-
|
12
|
+
s.date = %q{2012-02-15}
|
13
13
|
s.description = %q{Smilodon is a utility to parse data files.}
|
14
14
|
s.email = %q{uchouhan@optimiscorp.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,7 +35,9 @@ Gem::Specification.new do |s|
|
|
35
35
|
"smilodon.gemspec",
|
36
36
|
"spec/lib/smilodon_spec.rb",
|
37
37
|
"spec/lib/tasks/populate_spec.rb",
|
38
|
-
"spec/spec_helper.rb"
|
38
|
+
"spec/spec_helper.rb",
|
39
|
+
"spec/test_files/bar.csv",
|
40
|
+
"spec/test_files/foo.csv"
|
39
41
|
]
|
40
42
|
s.homepage = %q{http://github.com/optimis/smilodon}
|
41
43
|
s.licenses = ["MIT"]
|
data/spec/lib/smilodon_spec.rb
CHANGED
@@ -62,6 +62,12 @@ describe FakePopulator, '.files' do
|
|
62
62
|
FakePopulatorWithMultipleFiles.files.each { |f| FakePopulatorWithMultipleFiles.should_receive(:read).with(f).and_return('') }
|
63
63
|
FakePopulatorWithMultipleFiles.run
|
64
64
|
end
|
65
|
+
|
66
|
+
context 'given a directory and no files' do
|
67
|
+
it 'sets files to all the files in directory' do
|
68
|
+
FakePopulatorWithOnlyDirectory.files.should == ['bar', 'foo']
|
69
|
+
end
|
70
|
+
end
|
65
71
|
end
|
66
72
|
|
67
73
|
describe FakePopulator, '.run' do
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smilodon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 8
|
10
|
+
version: 0.2.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Umang Chouhan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-15 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -139,6 +139,8 @@ files:
|
|
139
139
|
- spec/lib/smilodon_spec.rb
|
140
140
|
- spec/lib/tasks/populate_spec.rb
|
141
141
|
- spec/spec_helper.rb
|
142
|
+
- spec/test_files/bar.csv
|
143
|
+
- spec/test_files/foo.csv
|
142
144
|
has_rdoc: true
|
143
145
|
homepage: http://github.com/optimis/smilodon
|
144
146
|
licenses:
|