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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b4fa0eb73ae4be19bf5c40473f3015d008127f0
4
- data.tar.gz: 7258ee79e604d5fd2698ca7987ff2e617ec87875
3
+ metadata.gz: 48a7a492d5142f1d19b80c34a209bebbab1c349b
4
+ data.tar.gz: ae1893bd435ef69c849cf4dc15ad5df9028855b9
5
5
  SHA512:
6
- metadata.gz: 55d0a0a264ff0f404e1fd55d122aba626b740dbe4e42b8638055123e7b0d3d4ed7fcf397e3717e93442a25f2715494c3b6d1776144b3a22dd4e9f29aa1d75031
7
- data.tar.gz: 7a5c75411dc268e9d6eb7fc7578f292b1d1a0757525bc2d0d2923f284fa3b64a33207eb6e3e09bc95db42d4d89c519a975e12055194e26238b14ac96176e4a45
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
@@ -4,6 +4,7 @@ gemspec
4
4
 
5
5
  group :test do
6
6
  gem 'rom', git: 'https://github.com/rom-rb/rom.git', branch: 'master'
7
+ gem 'virtus'
7
8
  gem 'rspec', '~> 3.1'
8
9
  gem 'codeclimate-test-reporter', require: false
9
10
  gem 'inflecto'
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'bundler/gem_tasks'
1
2
  require 'rspec/core/rake_task'
2
3
 
3
4
  RSpec::Core::RakeTask.new(:spec)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module CSV
3
- VERSION = '0.0.1'.freeze
3
+ VERSION = '0.1.0'.freeze
4
4
  end
5
5
  end
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'
@@ -1,3 +1,4 @@
1
1
  id,name,email
2
2
  1,Julie,julie.andrews@example.com
3
- 2,Jane,jane@doe.org
3
+ 2,Julie,julie@doe.org
4
+ 3,Jane,jane@doe.org
@@ -0,0 +1,5 @@
1
+ id;name;email
2
+ 1;Julie;julie.andrews@example.com
3
+ 2;Julie;julie@doe.org
4
+ 3;Jane;jane@doe.org
5
+ 4;Żółw;zolw@example.com
@@ -1,41 +1,90 @@
1
1
  require 'spec_helper'
2
- require 'anima'
2
+ require 'virtus'
3
3
 
4
4
  describe 'CSV repository' do
5
- subject(:rom) { setup.finalize }
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
- let(:path) { File.expand_path('./spec/fixtures/users.csv') }
11
+ before do
12
+ setup.relation(:users) do
13
+ def by_name(name)
14
+ restrict(name: name)
15
+ end
8
16
 
9
- # If :csv is not passed in the repository is named `:default`
10
- let(:setup) { ROM.setup(:csv, path) }
17
+ def only_name
18
+ project(:name)
19
+ end
11
20
 
12
- before do
13
- setup.relation(:users) do
14
- def by_name(name)
15
- restrict(name: name)
21
+ def ordered
22
+ order(:name, :email)
23
+ end
16
24
  end
17
- end
18
25
 
19
- class User
20
- # Anima allows creation of an instance with an attribute hash
21
- include Anima.new(:id, :name, :email)
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
- setup.mappers do
25
- define(:users) do
26
- model User
27
- register_as :entity
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
- describe 'env#relation' do
33
- it 'returns mapped object' do
34
- jane = rom.relation(:users).as(:entity).by_name('Jane').to_a.first
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
- expect(jane.id).to eql(2)
37
- expect(jane.name).to eql('Jane')
38
- expect(jane.email).to eql('jane@doe.org')
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.1
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-03-22 00:00:00.000000000 Z
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.4.5
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