smilodon 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +37 -0
- data/Rakefile +10 -0
- data/VERSION +1 -0
- data/lib/smilodon/errors.rb +32 -0
- data/lib/smilodon/fakes.rb +49 -0
- data/lib/smilodon/tasks.rb +1 -0
- data/lib/smilodon.rb +128 -0
- data/lib/tasks/populate.rake +31 -0
- data/lib/tasks/populate.yml +2 -0
- data/smilodon.gemspec +74 -0
- data/spec/lib/smilodon_spec.rb +114 -0
- data/spec/lib/tasks/populate_spec.rb +14 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/test_files/bar.csv +0 -0
- data/spec/test_files/foo.csv +0 -0
- metadata +176 -0
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
rake (0.9.2.2)
|
6
|
+
rspec (2.10.0)
|
7
|
+
rspec-core (~> 2.10.0)
|
8
|
+
rspec-expectations (~> 2.10.0)
|
9
|
+
rspec-mocks (~> 2.10.0)
|
10
|
+
rspec-core (2.10.0)
|
11
|
+
rspec-expectations (2.10.0)
|
12
|
+
diff-lcs (~> 1.1.3)
|
13
|
+
rspec-mocks (2.10.1)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
rake
|
20
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Umang Chouhan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
== Populator http://travis-ci.org/optimis/populator.png
|
2
|
+
|
3
|
+
http://www.paleospot.com/illustrations/Smilodon.jpg
|
4
|
+
|
5
|
+
Populator includes helper methods to ease parsing data files. Assigning a header and iterating over rows is handled by the module via a simple configuration.
|
6
|
+
|
7
|
+
Examples:
|
8
|
+
|
9
|
+
Define a module and extend it with the populator module.
|
10
|
+
|
11
|
+
A Custom Populator.
|
12
|
+
|
13
|
+
module CustomPopulator
|
14
|
+
extend Populator
|
15
|
+
populates 'CustomFile'
|
16
|
+
|
17
|
+
def process(row)
|
18
|
+
...
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
The extended module focusses on business logic required to process a single row.
|
23
|
+
|
24
|
+
== Contributing to populator
|
25
|
+
|
26
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
27
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
28
|
+
* Fork the project.
|
29
|
+
* Start a feature/bugfix branch.
|
30
|
+
* Commit and push until you are happy with your contribution.
|
31
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
32
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
33
|
+
|
34
|
+
== Copyright
|
35
|
+
|
36
|
+
Copyright (c) 2011 Umang Chouhan. See LICENSE.txt for
|
37
|
+
further details.
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.9
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# The exception class used when the data file is not configured.
|
2
|
+
class DataFileNotConfigured < Exception
|
3
|
+
|
4
|
+
# Set the message to return when a data file is not configured.
|
5
|
+
#
|
6
|
+
# @return [String] The message to return if the data file is not configured.
|
7
|
+
def message
|
8
|
+
'No data file was specified. Usage: populates <file>'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# The exception class used when the data file is missing.
|
13
|
+
class MissingDataFile < Exception
|
14
|
+
|
15
|
+
# Set the message to return when a data file is missing.
|
16
|
+
#
|
17
|
+
# @return [String] The message to return if the data file is missing.
|
18
|
+
def message
|
19
|
+
'The data file configured is missing.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# The exception class used when the process method is not overridden.
|
24
|
+
class MethodNotOverridden < Exception
|
25
|
+
|
26
|
+
# Set the message to return when the process method is not overridden.
|
27
|
+
#
|
28
|
+
# @return [String] The message to return when the process method is not overridden.
|
29
|
+
def message
|
30
|
+
'You must override the .process method in the extended populator class.'
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# A fake populator module with default type for testing.
|
2
|
+
module FakePopulator
|
3
|
+
|
4
|
+
# Extend it with the Populator module.
|
5
|
+
extend Smilodon::Populator
|
6
|
+
|
7
|
+
# Populate the test file.
|
8
|
+
populates 'TestFile'
|
9
|
+
end
|
10
|
+
|
11
|
+
# A fake populator module with overridden type for testing.
|
12
|
+
module FakePopulatorWithOverriddenType
|
13
|
+
|
14
|
+
# Extend it with the Populator module.
|
15
|
+
extend Smilodon::Populator
|
16
|
+
|
17
|
+
# Populate the test excel file.
|
18
|
+
populates 'TestExcelFile', :type => 'excel'
|
19
|
+
end
|
20
|
+
|
21
|
+
# A fake populator module with overridden directory for testing.
|
22
|
+
module FakePopulatorWithOverriddenDirectory
|
23
|
+
|
24
|
+
# Extend it with the Populator module.
|
25
|
+
extend Smilodon::Populator
|
26
|
+
|
27
|
+
# Populate the test file.
|
28
|
+
populates 'TestFile', :directory => 'db/populate/files'
|
29
|
+
end
|
30
|
+
|
31
|
+
# A fake populator module with overridden directory for testing.
|
32
|
+
module FakePopulatorWithMultipleFiles
|
33
|
+
|
34
|
+
# Extend it with the Populator module.
|
35
|
+
extend Smilodon::Populator
|
36
|
+
|
37
|
+
# Populate the test file.
|
38
|
+
populates 'TestFile1', 'TestFile2', 'TestFile3', :directory => 'db/populate/files'
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
load 'tasks/populate.rake'
|
data/lib/smilodon.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'smilodon/errors'
|
4
|
+
require 'smilodon/railtie' if defined?(Rails)
|
5
|
+
|
6
|
+
# Smilodon includes helper methods to ease parsing data files.
|
7
|
+
# Assigning a header and iterating over rows is handled by the
|
8
|
+
# module via a simple configuration.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# Define a module and extend it with the populator module.
|
12
|
+
#
|
13
|
+
# @example A Custom Populator.
|
14
|
+
# module CustomPopulator
|
15
|
+
# extend Populator
|
16
|
+
# populates 'CustomFile'
|
17
|
+
#
|
18
|
+
# def process(row)
|
19
|
+
# ...
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# @note As noted in the example the extended module defines the
|
24
|
+
# logic to process a single row.
|
25
|
+
|
26
|
+
module Smilodon
|
27
|
+
module Populator
|
28
|
+
|
29
|
+
# Default directory location for data files.
|
30
|
+
DIRECTORY = 'files'
|
31
|
+
|
32
|
+
# Default data file type is CSV.
|
33
|
+
TYPE = 'csv'
|
34
|
+
|
35
|
+
# Attribute accessors for the directory, file name, header, rows and before hook.
|
36
|
+
attr_accessor :logger, :directory, :files, :type, :header, :rows, :before
|
37
|
+
|
38
|
+
# Configuration helper.
|
39
|
+
#
|
40
|
+
# @param [Array] args an array of strings with an optional options hash
|
41
|
+
# @option options [String] :directory ('db/populate/data_files') The location of the data file.
|
42
|
+
# @option options [String] :type ('csv') The data file type.
|
43
|
+
# @option options [Boolean] :header Set true if the file has a header.
|
44
|
+
# @option options [String] :before The method to call before the run.
|
45
|
+
def populates(*args)
|
46
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
47
|
+
|
48
|
+
self.directory = if defined?(Rails)
|
49
|
+
"#{Rails.root}/#{options[:directory] || DIRECTORY}"
|
50
|
+
else
|
51
|
+
options[:directory] || DIRECTORY
|
52
|
+
end
|
53
|
+
|
54
|
+
self.type = options[:type] || TYPE
|
55
|
+
self.header = options[:header]
|
56
|
+
self.before = options[:before]
|
57
|
+
self.files = args.empty? ? grab_files : args
|
58
|
+
end
|
59
|
+
|
60
|
+
# Parses the data file content and processes each row.
|
61
|
+
#
|
62
|
+
# @return [Boolean] Returns true if all rows are processed successfully.
|
63
|
+
def run
|
64
|
+
files.each do |f|
|
65
|
+
# Call the before hook if defined.
|
66
|
+
#
|
67
|
+
# @usage
|
68
|
+
# populates 'TestFile', :before => :inactivate
|
69
|
+
send(before) if before
|
70
|
+
rows = parser.parse(read(f))
|
71
|
+
rows.each_with_index do |row, index|
|
72
|
+
if index == 0 && header
|
73
|
+
self.header = row
|
74
|
+
else
|
75
|
+
process(row)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return true when all rows are processed.
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
# Stub method to be defined in the extended module.
|
85
|
+
#
|
86
|
+
# @raise [Exception] Raises an exception if the extended module does not override the method.
|
87
|
+
def process(row = nil)
|
88
|
+
raise MethodNotOverridden
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def grab_files
|
93
|
+
Dir.glob("#{directory}/*").map do |file|
|
94
|
+
File.basename(file, File.extname(file))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# The parser to use based on the type of data file.
|
99
|
+
#
|
100
|
+
# @param [String] Name of file to be read
|
101
|
+
# @return [Parser, #parse] Returns the parser class to use.
|
102
|
+
def parser
|
103
|
+
if type == 'csv'
|
104
|
+
require 'csv'
|
105
|
+
return CSV::Reader
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Absolute path for the data file.
|
110
|
+
#
|
111
|
+
# @return [String] The absolute path.
|
112
|
+
def path(file)
|
113
|
+
"#{directory}/#{file}.#{type}"
|
114
|
+
end
|
115
|
+
|
116
|
+
# Reads the data file.
|
117
|
+
#
|
118
|
+
# @param [String] Name of file to be read
|
119
|
+
# @return [File] The data file contents.
|
120
|
+
# @raise [DataFileNotConfigured] Raises an exception when the file is not configured.
|
121
|
+
# @raise [MissingDataFile] Raises an exception when the configured file is missing.
|
122
|
+
def read(file)
|
123
|
+
raise DataFileNotConfigured unless file
|
124
|
+
raise MissingDataFile unless File.exist?(path(file))
|
125
|
+
File.read path(file)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
namespace :db do
|
4
|
+
desc 'Runs the populators defined in the configuration file'
|
5
|
+
|
6
|
+
task :populate => :environment do
|
7
|
+
populators.each do |populator|
|
8
|
+
if defined?(Rails)
|
9
|
+
require "#{Rails.root}/db/populate/#{populator}"
|
10
|
+
Kernel.const_get(populator.split('_').collect(&:capitalize).join).run
|
11
|
+
else
|
12
|
+
Kernel.const_get(populator).run
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def path
|
19
|
+
defined?(Rails) ? "#{Rails.root}/config/populate.yml" : "populate.yml"
|
20
|
+
end
|
21
|
+
|
22
|
+
def configuration
|
23
|
+
@configuration ||= YAML.load_file(path)
|
24
|
+
rescue
|
25
|
+
raise Exception, 'Missing configuration file. Add a populate.yml in the project directory or in the config/ directory for rails projects.' unless File.exists?(path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def populators
|
29
|
+
defined?(Rails) ? configuration['populators'] : configuration[:populators]
|
30
|
+
end
|
31
|
+
end
|
data/smilodon.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "smilodon"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Umang Chouhan"]
|
12
|
+
s.date = "2012-07-25"
|
13
|
+
s.description = "Smilodon is a utility to parse data files."
|
14
|
+
s.email = "uchouhan@optimiscorp.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/smilodon.rb",
|
29
|
+
"lib/smilodon/errors.rb",
|
30
|
+
"lib/smilodon/fakes.rb",
|
31
|
+
"lib/smilodon/tasks.rb",
|
32
|
+
"lib/tasks/populate.rake",
|
33
|
+
"lib/tasks/populate.yml",
|
34
|
+
"smilodon.gemspec",
|
35
|
+
"spec/lib/smilodon_spec.rb",
|
36
|
+
"spec/lib/tasks/populate_spec.rb",
|
37
|
+
"spec/spec_helper.rb",
|
38
|
+
"spec/test_files/bar.csv",
|
39
|
+
"spec/test_files/foo.csv"
|
40
|
+
]
|
41
|
+
s.homepage = "http://github.com/optimis/smilodon"
|
42
|
+
s.licenses = ["MIT"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = "1.8.15"
|
45
|
+
s.summary = "Smilodon is a utility to parse data files."
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<logging>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<logging>, [">= 0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
62
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
63
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<logging>, [">= 0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
70
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'smilodon/fakes'
|
3
|
+
|
4
|
+
describe Smilodon::Populator, 'DIRECTORY' do
|
5
|
+
it 'should be set to the default directory' do
|
6
|
+
Smilodon::Populator::DIRECTORY.should == 'files'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe FakePopulator, '.directory' do
|
11
|
+
context 'when no directory is configured' do
|
12
|
+
it 'should return the default directory' do
|
13
|
+
FakePopulator.directory.should == Smilodon::Populator::DIRECTORY
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when the directory is configured' do
|
18
|
+
it 'should return the configured directory' do
|
19
|
+
FakePopulatorWithOverriddenDirectory.directory.should == 'db/populate/files'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe FakePopulator, '.file' do
|
25
|
+
it 'should return the configured file name' do
|
26
|
+
FakePopulator.files.should == ['TestFile']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe FakePopulator, '.type' do
|
31
|
+
context 'when no file type is configured' do
|
32
|
+
it 'should return the default file type' do
|
33
|
+
FakePopulator.type.should == 'csv'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when the file type is configured' do
|
38
|
+
it 'should return the configured file type' do
|
39
|
+
FakePopulatorWithOverriddenType.type.should == 'excel'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe FakePopulator, '.process(row)' do
|
45
|
+
it 'should raise an exception with a message to define the method in the extended populator class' do
|
46
|
+
lambda {
|
47
|
+
FakePopulator.process
|
48
|
+
}.should raise_exception(MethodNotOverridden)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe FakePopulator, '.files' do
|
53
|
+
it 'should return the configured file names' do
|
54
|
+
FakePopulatorWithMultipleFiles.files.should == ['TestFile1', 'TestFile2', 'TestFile3']
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should handle an options hash' do
|
58
|
+
FakePopulatorWithMultipleFiles.directory.should == 'db/populate/files'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'calls read for each file passed to populate' do
|
62
|
+
FakePopulatorWithMultipleFiles.files.each { |f| FakePopulatorWithMultipleFiles.should_receive(:read).with(f).and_return('') }
|
63
|
+
FakePopulatorWithMultipleFiles.run
|
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.sort.should == ['bar', 'foo'].sort
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe FakePopulator, '.run' do
|
74
|
+
module TestPopulator
|
75
|
+
extend Smilodon::Populator
|
76
|
+
populates 'abc'
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'header is true' do
|
80
|
+
let!(:csv) { ["id,name", "1,atsuya"].join("\n") }
|
81
|
+
|
82
|
+
before do
|
83
|
+
TestPopulator.header = true
|
84
|
+
TestPopulator.stub(:read).and_return(csv)
|
85
|
+
TestPopulator.should_receive(:process).once
|
86
|
+
TestPopulator.run
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should process csv file' do
|
90
|
+
TestPopulator.header.should == ["id", "name"]
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'calls process for each non-header row' do
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'header is false' do
|
98
|
+
let!(:csv) { ["id,name", "1,atsuya"].join("\n") }
|
99
|
+
|
100
|
+
before do
|
101
|
+
TestPopulator.header = false
|
102
|
+
TestPopulator.stub(:read).and_return(csv)
|
103
|
+
TestPopulator.should_receive(:process).twice
|
104
|
+
TestPopulator.run
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should process csv file' do
|
108
|
+
TestPopulator.header.should == false
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'calls process for each row' do
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'smilodon/fakes'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
load 'tasks/populate.rake'
|
6
|
+
|
7
|
+
describe 'db:populate' do
|
8
|
+
it 'should run the fake populator' do
|
9
|
+
Rake::Task.define_task :environment
|
10
|
+
YAML.stub(:load_file).and_return({ :populators => [ 'FakePopulator' ]})
|
11
|
+
FakePopulator.should_receive :run
|
12
|
+
Rake::Task['db:populate'].invoke
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'smilodon'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
File without changes
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smilodon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Umang Chouhan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-07-25 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
requirement: *id001
|
32
|
+
name: logging
|
33
|
+
type: :runtime
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 15
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 6
|
45
|
+
- 0
|
46
|
+
version: 1.6.0
|
47
|
+
requirement: *id002
|
48
|
+
name: jeweler
|
49
|
+
type: :development
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 23
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 0
|
61
|
+
- 0
|
62
|
+
version: 1.0.0
|
63
|
+
requirement: *id003
|
64
|
+
name: bundler
|
65
|
+
type: :development
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 2
|
76
|
+
- 3
|
77
|
+
- 0
|
78
|
+
version: 2.3.0
|
79
|
+
requirement: *id004
|
80
|
+
name: rspec
|
81
|
+
type: :development
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirement: *id005
|
94
|
+
name: rcov
|
95
|
+
type: :development
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 7
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
- 6
|
107
|
+
- 0
|
108
|
+
version: 0.6.0
|
109
|
+
requirement: *id006
|
110
|
+
name: yard
|
111
|
+
type: :development
|
112
|
+
description: Smilodon is a utility to parse data files.
|
113
|
+
email: uchouhan@optimiscorp.com
|
114
|
+
executables: []
|
115
|
+
|
116
|
+
extensions: []
|
117
|
+
|
118
|
+
extra_rdoc_files:
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.rdoc
|
121
|
+
files:
|
122
|
+
- .document
|
123
|
+
- .rspec
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.rdoc
|
128
|
+
- Rakefile
|
129
|
+
- VERSION
|
130
|
+
- lib/smilodon.rb
|
131
|
+
- lib/smilodon/errors.rb
|
132
|
+
- lib/smilodon/fakes.rb
|
133
|
+
- lib/smilodon/tasks.rb
|
134
|
+
- lib/tasks/populate.rake
|
135
|
+
- lib/tasks/populate.yml
|
136
|
+
- smilodon.gemspec
|
137
|
+
- spec/lib/smilodon_spec.rb
|
138
|
+
- spec/lib/tasks/populate_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/test_files/bar.csv
|
141
|
+
- spec/test_files/foo.csv
|
142
|
+
homepage: http://github.com/optimis/smilodon
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
hash: 3
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
version: "0"
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
hash: 3
|
165
|
+
segments:
|
166
|
+
- 0
|
167
|
+
version: "0"
|
168
|
+
requirements: []
|
169
|
+
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 1.8.15
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: Smilodon is a utility to parse data files.
|
175
|
+
test_files: []
|
176
|
+
|