rom-csv 0.0.1 → 0.1.0
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 +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -0
- data/Rakefile +1 -0
- data/lib/rom/csv/repository.rb +3 -2
- data/lib/rom/csv/version.rb +1 -1
- data/rom-csv.gemspec +0 -1
- data/spec/fixtures/users.csv +2 -1
- data/spec/fixtures/users.utf-8.csv +5 -0
- data/spec/integration/repository_spec.rb +73 -24
- metadata +5 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48a7a492d5142f1d19b80c34a209bebbab1c349b
|
4
|
+
data.tar.gz: ae1893bd435ef69c849cf4dc15ad5df9028855b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac7adf3da1e06b6b8908149bc338d1bcdbeb800ea67e606ba76318fd0ae2d5a012300ecc9c0e28bb2468b29516ce9a1526838b87144b212c8e644d3b9415279
|
7
|
+
data.tar.gz: a912c91ebeebfb506233fc7dba5caa1467554b91352e65d3f346c9a9eef25453e802f315b99a0d92924e84b642bf4c3f67c8194c3034b2dd491457476f3fcd3f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## v0.1.0 2015-04-16
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Allow to call repository with extra `CSV` options (gotar)
|
6
|
+
|
7
|
+
### Internal
|
8
|
+
|
9
|
+
* Improve test coverage (wafcio)
|
10
|
+
|
11
|
+
[Compare v0.0.1...v0.1.0](https://github.com/rom-rb/rom/compare/v0.0.1...v0.1.0)
|
12
|
+
|
1
13
|
## v0.0.1 2015-03-22
|
2
14
|
|
3
15
|
First public release
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/rom/csv/repository.rb
CHANGED
@@ -48,13 +48,14 @@ module ROM
|
|
48
48
|
# * header_converters: :symbol
|
49
49
|
#
|
50
50
|
# @param path [String] path to csv
|
51
|
+
# @param options [Hash] options passed to CSV.table
|
51
52
|
#
|
52
53
|
# @api private
|
53
54
|
#
|
54
55
|
# @see CSV.table
|
55
|
-
def initialize(path)
|
56
|
+
def initialize(path, options = {})
|
56
57
|
@datasets = {}
|
57
|
-
@connection = ::CSV.table(path).by_row!
|
58
|
+
@connection = ::CSV.table(path, options).by_row!
|
58
59
|
end
|
59
60
|
|
60
61
|
# Return dataset with the given name
|
data/lib/rom/csv/version.rb
CHANGED
data/rom-csv.gemspec
CHANGED
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'rom', '~> 0.6.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency 'anima'
|
24
23
|
spec.add_development_dependency 'bundler'
|
25
24
|
spec.add_development_dependency 'rake'
|
26
25
|
spec.add_development_dependency 'rubocop', '~> 0.28.0'
|
data/spec/fixtures/users.csv
CHANGED
@@ -1,41 +1,90 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
2
|
+
require 'virtus'
|
3
3
|
|
4
4
|
describe 'CSV repository' do
|
5
|
-
|
5
|
+
context 'without extra options' do
|
6
|
+
# If :csv is not passed in the repository is named `:default`
|
7
|
+
let(:path) { File.expand_path('./spec/fixtures/users.csv') }
|
8
|
+
let(:setup) { ROM.setup(:csv, path) }
|
9
|
+
subject(:rom) { setup.finalize }
|
6
10
|
|
7
|
-
|
11
|
+
before do
|
12
|
+
setup.relation(:users) do
|
13
|
+
def by_name(name)
|
14
|
+
restrict(name: name)
|
15
|
+
end
|
8
16
|
|
9
|
-
|
10
|
-
|
17
|
+
def only_name
|
18
|
+
project(:name)
|
19
|
+
end
|
11
20
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
restrict(name: name)
|
21
|
+
def ordered
|
22
|
+
order(:name, :email)
|
23
|
+
end
|
16
24
|
end
|
17
|
-
end
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
class User
|
27
|
+
include Virtus.model
|
28
|
+
|
29
|
+
attribute :id, Integer
|
30
|
+
attribute :name, String
|
31
|
+
attribute :email, String
|
32
|
+
end
|
33
|
+
|
34
|
+
setup.mappers do
|
35
|
+
define(:users) do
|
36
|
+
model User
|
37
|
+
register_as :entity
|
38
|
+
end
|
39
|
+
end
|
22
40
|
end
|
23
41
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
42
|
+
describe 'env#relation' do
|
43
|
+
it 'returns restricted and mapped object' do
|
44
|
+
jane = rom.relation(:users).as(:entity).by_name('Jane').to_a.first
|
45
|
+
|
46
|
+
expect(jane.id).to eql(3)
|
47
|
+
expect(jane.name).to eql('Jane')
|
48
|
+
expect(jane.email).to eql('jane@doe.org')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns specified attributes in mapped object' do
|
52
|
+
jane = rom.relation(:users).as(:entity).only_name.to_a.first
|
53
|
+
|
54
|
+
expect(jane.id).to be_nil
|
55
|
+
expect(jane.name).not_to be_nil
|
56
|
+
expect(jane.email).to be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'return ordered attributes by name and email' do
|
60
|
+
results = rom.relation(:users).as(:entity).ordered.to_a
|
61
|
+
|
62
|
+
expect(results[0].name).to eql('Jane')
|
63
|
+
expect(results[0].email).to eq('jane@doe.org')
|
64
|
+
|
65
|
+
expect(results[1].name).to eql('Julie')
|
66
|
+
expect(results[1].email).to eq('julie.andrews@example.com')
|
67
|
+
|
68
|
+
expect(results[2].name).to eql('Julie')
|
69
|
+
expect(results[2].email).to eq('julie@doe.org')
|
28
70
|
end
|
29
71
|
end
|
30
|
-
end
|
31
72
|
|
32
|
-
|
33
|
-
|
34
|
-
|
73
|
+
context 'with custom options' do
|
74
|
+
let(:path) { File.expand_path('./spec/fixtures/users.utf-8.csv') }
|
75
|
+
let(:options) { { encoding: 'iso-8859-2', col_sep: ';' } }
|
35
76
|
|
36
|
-
|
37
|
-
|
38
|
-
|
77
|
+
it 'allows to force encoding' do
|
78
|
+
setup = ROM.setup(:csv, path, options)
|
79
|
+
setup.relation(:users)
|
80
|
+
rom = setup.finalize
|
81
|
+
user = rom.relation(:users).to_a.last
|
82
|
+
|
83
|
+
expect(user[:id]).to eql(4)
|
84
|
+
expect(user[:name].bytes.to_a)
|
85
|
+
.to eql("\xC5\xBB\xC3\xB3\xC5\x82w".bytes.to_a)
|
86
|
+
expect(user[:email]).to eql('zolw@example.com')
|
87
|
+
end
|
39
88
|
end
|
40
89
|
end
|
41
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rom
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.6.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: anima
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,6 +96,7 @@ files:
|
|
110
96
|
- rakelib/rubocop.rake
|
111
97
|
- rom-csv.gemspec
|
112
98
|
- spec/fixtures/users.csv
|
99
|
+
- spec/fixtures/users.utf-8.csv
|
113
100
|
- spec/integration/repository_spec.rb
|
114
101
|
- spec/spec_helper.rb
|
115
102
|
- spec/unit/dataset_spec.rb
|
@@ -134,12 +121,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
121
|
version: '0'
|
135
122
|
requirements: []
|
136
123
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.2.2
|
138
125
|
signing_key:
|
139
126
|
specification_version: 4
|
140
127
|
summary: CSV support for Ruby Object Mapper
|
141
128
|
test_files:
|
142
129
|
- spec/fixtures/users.csv
|
130
|
+
- spec/fixtures/users.utf-8.csv
|
143
131
|
- spec/integration/repository_spec.rb
|
144
132
|
- spec/spec_helper.rb
|
145
133
|
- spec/unit/dataset_spec.rb
|