rom-csv 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50f29f9955ae5aa228873154052cb12ea961f582
4
- data.tar.gz: 3979e8a009b8725a7a5280703e29bc89259ac512
3
+ metadata.gz: 785fc82ce3b26b8c689e96b6f7726be09737fc04
4
+ data.tar.gz: 5a7806a367a01478c6a6531bc73356ceb9cacef6
5
5
  SHA512:
6
- metadata.gz: 03fb8e82792ea55ed6b72ff437d4c8c1381a24e980f82b0fe32c7df16b9a0473ea8e87cdb907498abe3d703cf1289f746b09493e059e22427d413e73173fff35
7
- data.tar.gz: 9d6f4ab54cef76ed4f27b8c28a142dd6999f905ac1cb2d4daceab3c9d7bb32ae502b435048d790072878f57f32f11b66402dc5e0dcaa10be91c2bfff5178e462
6
+ metadata.gz: cd6265073e0ace7189e5eccffc40d51685381e607d17e3d5f4dd6affe311d38fa25623afa1758963c6a1ee85cdafe4a5c363f0af8f4c3771a8d3db9416ea7bcf
7
+ data.tar.gz: b467d48226beae9684bfa297adcd5a59bc1cf095987980aea7c8bb34ac8b1b7dacb88c6ff183667de771b78fac3805d77baa128a349a921f2456d3cfba2b92f4
@@ -19,7 +19,7 @@ Style/AsciiComments:
19
19
  Enabled: false
20
20
 
21
21
  # Allow using braces for value-returning blocks
22
- Style/Blocks:
22
+ Style/BlockDelimiters:
23
23
  Enabled: false
24
24
 
25
25
  # Documentation checked by Inch CI
@@ -38,10 +38,6 @@ Style/Lambda:
38
38
  Style/MultilineBlockChain:
39
39
  Enabled: false
40
40
 
41
- # Even a single escaped slash can be confusing
42
- Style/RegexpLiteral:
43
- MaxSlashes: 0
44
-
45
41
  # Don’t introduce semantic fail/raise distinction
46
42
  Style/SignalException:
47
43
  EnforcedStyle: only_raise
@@ -7,8 +7,9 @@ rvm:
7
7
  - 2.0
8
8
  - 2.1
9
9
  - 2.2
10
+ - 2.3.0
10
11
  - rbx-2
11
- - jruby
12
+ - jruby-9000
12
13
  - ruby-head
13
14
  matrix:
14
15
  allow_failures:
@@ -1,3 +1,7 @@
1
+ ## v0.3.0 2016-02-22
2
+
3
+ * Update dependency to ROM 1.0
4
+
1
5
  ## v0.2.0 2015-08-19
2
6
 
3
7
  ### Added
@@ -6,11 +6,10 @@ require 'ostruct'
6
6
 
7
7
  csv_file = ARGV[0] || File.expand_path("./users.csv", File.dirname(__FILE__))
8
8
 
9
- ROM.use :auto_registration
9
+ configuration = ROM::Configuration.new(:csv, csv_file)
10
+ configuration.use(:macros)
10
11
 
11
- setup = ROM.setup(:csv, csv_file)
12
-
13
- setup.relation(:users) do
12
+ configuration.relation(:users) do
14
13
  def by_name(name)
15
14
  restrict(name: name)
16
15
  end
@@ -19,15 +18,16 @@ end
19
18
  class User < OpenStruct
20
19
  end
21
20
 
22
- setup.mappers do
21
+ configuration.mappers do
23
22
  define(:users) do
24
23
  register_as :entity
25
24
  model User
26
25
  end
27
26
  end
28
27
 
29
- rom = setup.finalize
30
- user = rom.relation(:users).as(:entity).by_name('Jane').one
28
+ container = ROM.container(configuration)
29
+
30
+ user = container.relation(:users).as(:entity).by_name('Jane').one
31
31
  # => #<User id=2, name="Jane", email="jane@doe.org">
32
32
 
33
33
  user or abort "user not found"
@@ -8,7 +8,7 @@ module ROM
8
8
  adapter :csv
9
9
 
10
10
  def execute(tuples)
11
- insert_tuples = [tuples].flatten.map do |tuple|
11
+ insert_tuples = [tuples].flatten.map do |tuple|
12
12
  attributes = input[tuple]
13
13
  validator.call(attributes)
14
14
  attributes.to_h
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module CSV
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_runtime_dependency 'rom', '~> 0.9', '>= 0.9.0'
21
+ spec.add_runtime_dependency 'rom', '~> 1.0'
22
22
 
23
23
  spec.add_development_dependency 'bundler'
24
24
  spec.add_development_dependency 'rake'
@@ -2,20 +2,12 @@ require 'spec_helper'
2
2
  require 'virtus'
3
3
 
4
4
  describe 'Commands / Create' do
5
- subject(:rom) { setup.finalize }
5
+ include_context 'database setup'
6
6
 
7
- let(:original_path) { File.expand_path('./spec/fixtures/users.csv') }
8
- let(:path) { File.expand_path('./spec/fixtures/testing.csv') }
9
-
10
- # If :csv is not passed in the gateway is named `:default`
11
- let(:setup) { ROM.setup(:csv, path) }
12
-
13
- subject(:users) { rom.commands.users }
7
+ subject(:users) { container.commands.users }
14
8
 
15
9
  before do
16
- FileUtils.copy(original_path, path)
17
-
18
- setup.relation(:users)
10
+ configuration.relation(:users)
19
11
 
20
12
  class User
21
13
  include Virtus.model
@@ -25,14 +17,14 @@ describe 'Commands / Create' do
25
17
  attribute :email, String
26
18
  end
27
19
 
28
- setup.mappers do
20
+ configuration.mappers do
29
21
  define(:users) do
30
22
  model User
31
23
  register_as :entity
32
24
  end
33
25
  end
34
26
 
35
- setup.commands(:users) do
27
+ configuration.commands(:users) do
36
28
  define(:create) do
37
29
  result :one
38
30
  end
@@ -49,7 +41,7 @@ describe 'Commands / Create' do
49
41
  end
50
42
  expect(result.value).to eql(user_id: 4, name: 'John', email: 'john@doe.org')
51
43
 
52
- result = rom.relation(:users).as(:entity).to_a
44
+ result = container.relation(:users).as(:entity).to_a
53
45
  expect(result.count).to eql(4)
54
46
  end
55
47
 
@@ -66,7 +58,7 @@ describe 'Commands / Create' do
66
58
  { user_id: 5, name: 'Jack', email: 'jack@doe.org' }
67
59
  ])
68
60
 
69
- result = rom.relation(:users).as(:entity).to_a
61
+ result = container.relation(:users).as(:entity).to_a
70
62
  expect(result.count).to eql(5)
71
63
  end
72
64
  end
@@ -1,26 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Commands / Delete' do
4
- subject(:rom) { setup.finalize }
4
+ include_context 'database setup'
5
5
 
6
- let(:original_path) { File.expand_path('./spec/fixtures/users.csv') }
7
- let(:path) { File.expand_path('./spec/fixtures/testing.csv') }
8
-
9
- # If :csv is not passed in the gateway is named `:default`
10
- let(:setup) { ROM.setup(:csv, path) }
11
-
12
- subject(:users) { rom.commands.users }
6
+ subject(:users) { container.commands.users }
13
7
 
14
8
  before do
15
- FileUtils.copy(original_path, path)
16
-
17
- setup.relation(:users) do
9
+ configuration.relation(:users) do
18
10
  def by_id(id)
19
11
  restrict(user_id: id)
20
12
  end
21
13
  end
22
14
 
23
- setup.commands(:users) do
15
+ configuration.commands(:users) do
24
16
  define(:delete) do
25
17
  result :one
26
18
  end
@@ -40,9 +32,9 @@ describe 'Commands / Delete' do
40
32
  expect(result.value)
41
33
  .to eql(user_id: 1, name: "Julie", email: "julie.andrews@example.com")
42
34
 
43
- rom.relation(:users).dataset.reload!
35
+ container.relation(:users).dataset.reload!
44
36
 
45
- result = rom.relation(:users).to_a
37
+ result = container.relation(:users).to_a
46
38
  expect(result.count).to eql(2)
47
39
  end
48
40
  end
@@ -2,17 +2,11 @@ require 'spec_helper'
2
2
  require 'virtus'
3
3
 
4
4
  describe 'Commands / Updates' do
5
- subject(:rom) { setup.finalize }
5
+ include_context 'database setup'
6
6
 
7
- let(:original_path) { File.expand_path('./spec/fixtures/users.csv') }
8
- let(:path) { File.expand_path('./spec/fixtures/testing.csv') }
7
+ subject(:users) { container.commands.users }
9
8
 
10
- # If :csv is not passed in the gateway is named `:default`
11
- let(:setup) { ROM.setup(:csv, path) }
12
-
13
- subject(:users) { rom.commands.users }
14
-
15
- let(:relation) { rom.relations.users }
9
+ let(:relation) { container.relations.users }
16
10
  let(:first_data) { relation.by_id(1).to_a.first }
17
11
  let(:new_data) { { name: 'Peter' } }
18
12
  let(:output_data) do
@@ -20,9 +14,7 @@ describe 'Commands / Updates' do
20
14
  end
21
15
 
22
16
  before do
23
- FileUtils.copy(original_path, path)
24
-
25
- setup.relation(:users) do
17
+ configuration.relation(:users) do
26
18
  def by_id(id)
27
19
  restrict(user_id: id)
28
20
  end
@@ -36,14 +28,14 @@ describe 'Commands / Updates' do
36
28
  attribute :email, String
37
29
  end
38
30
 
39
- setup.mappers do
31
+ configuration.mappers do
40
32
  define(:users) do
41
33
  model User
42
34
  register_as :entity
43
35
  end
44
36
  end
45
37
 
46
- setup.commands(:users) do
38
+ configuration.commands(:users) do
47
39
  define(:update)
48
40
  end
49
41
  end
@@ -56,9 +48,9 @@ describe 'Commands / Updates' do
56
48
  expect(result.value.to_a).to match_array(output_data)
57
49
 
58
50
  # FIXME: reload! should not be necessary
59
- rom.relation(:users).dataset.reload!
51
+ container.relation(:users).dataset.reload!
60
52
 
61
- result = rom.relation(:users).as(:entity).by_id(1).to_a.first
53
+ result = container.relation(:users).as(:entity).by_id(1).to_a.first
62
54
  expect(result.email).to eql('tester@example.com')
63
55
  end
64
56
  end
@@ -3,13 +3,7 @@ require 'virtus'
3
3
 
4
4
  describe 'CSV gateway' do
5
5
  context 'without extra options' do
6
- # If :csv is not passed in the gateway is named `:default`
7
- let(:users_path) { File.expand_path('./spec/fixtures/users.csv') }
8
- let(:setup) do
9
- ROM.setup(
10
- users: [:csv, users_path]
11
- )
12
- end
6
+ include_context 'database setup'
13
7
 
14
8
  before do
15
9
  module TestPlugin; end
@@ -24,7 +18,7 @@ describe 'CSV gateway' do
24
18
  describe 'specify relation with plugin' do
25
19
  it "shouldn't raise error" do
26
20
  expect {
27
- setup.relation(:users) do
21
+ configuration.relation(:users) do
28
22
  gateway :users
29
23
  use :test_plugin
30
24
  end
@@ -3,19 +3,10 @@ require 'virtus'
3
3
 
4
4
  describe 'CSV gateway' do
5
5
  context 'without extra options' do
6
- # If :csv is not passed in the gateway is named `:default`
7
- let(:users_path) { File.expand_path('./spec/fixtures/users.csv') }
8
- let(:addresses_path) { File.expand_path('./spec/fixtures/addresses.csv') }
9
- let(:setup) do
10
- ROM.setup(
11
- users: [:csv, users_path],
12
- addresses: [:csv, addresses_path]
13
- )
14
- end
15
- subject(:rom) { setup.finalize }
6
+ include_context 'database setup'
16
7
 
17
8
  before do
18
- setup.relation(:users) do
9
+ configuration.relation(:users) do
19
10
  gateway :users
20
11
 
21
12
  def by_name(name)
@@ -35,7 +26,7 @@ describe 'CSV gateway' do
35
26
  end
36
27
  end
37
28
 
38
- setup.relation(:addresses) do
29
+ configuration.relation(:addresses) do
39
30
  gateway :addresses
40
31
  end
41
32
 
@@ -63,7 +54,7 @@ describe 'CSV gateway' do
63
54
  attribute :street, String
64
55
  end
65
56
 
66
- setup.mappers do
57
+ configuration.mappers do
67
58
  define(:users) do
68
59
  model User
69
60
  register_as :entity
@@ -85,14 +76,14 @@ describe 'CSV gateway' do
85
76
 
86
77
  describe 'env#relation' do
87
78
  it 'returns restricted and mapped object' do
88
- jane = rom.relation(:users).as(:entity).by_name('Jane').to_a.first
79
+ jane = container.relation(:users).as(:entity).by_name('Jane').to_a.first
89
80
 
90
81
  expect(jane.name).to eql('Jane')
91
82
  expect(jane.email).to eql('jane@doe.org')
92
83
  end
93
84
 
94
85
  it 'returns specified attributes in mapped object' do
95
- jane = rom.relation(:users).as(:entity).only_name.to_a.first
86
+ jane = container.relation(:users).as(:entity).only_name.to_a.first
96
87
 
97
88
  expect(jane.user_id).to be_nil
98
89
  expect(jane.name).not_to be_nil
@@ -100,7 +91,7 @@ describe 'CSV gateway' do
100
91
  end
101
92
 
102
93
  it 'return ordered attributes by name and email' do
103
- results = rom.relation(:users).as(:entity).ordered.to_a
94
+ results = container.relation(:users).as(:entity).ordered.to_a
104
95
 
105
96
  expect(results[0].name).to eql('Jane')
106
97
  expect(results[0].email).to eq('jane@doe.org')
@@ -113,7 +104,7 @@ describe 'CSV gateway' do
113
104
  end
114
105
 
115
106
  it 'returns joined data' do
116
- results = rom.relation(:users).as(:entity_with_address)
107
+ results = container.relation(:users).as(:entity_with_address)
117
108
  .with_addresses.first
118
109
 
119
110
  expect(results.attributes.keys.sort)
@@ -125,14 +116,14 @@ describe 'CSV gateway' do
125
116
  end
126
117
 
127
118
  context 'with custom options' do
128
- let(:path) { File.expand_path('./spec/fixtures/users.utf-8.csv') }
129
- let(:options) { { encoding: 'iso-8859-2', col_sep: ';' } }
119
+ before do
120
+ configuration.relation(:users_utf8) do
121
+ gateway :utf8
122
+ end
123
+ end
130
124
 
131
125
  it 'allows to force encoding' do
132
- setup = ROM.setup(:csv, path, options)
133
- setup.relation(:users)
134
- rom = setup.finalize
135
- user = rom.relation(:users).to_a.last
126
+ user = container.relation(:users_utf8).to_a.last
136
127
 
137
128
  expect(user[:id]).to eql(4)
138
129
  expect(user[:name].bytes.to_a)
@@ -13,6 +13,4 @@ require 'rom-csv'
13
13
 
14
14
  root = Pathname(__FILE__).dirname
15
15
 
16
- Dir[root.join('shared/*.rb').to_s].each { |f| require f }
17
-
18
- ROM.use :auto_registration
16
+ Dir[root.join('support/*.rb').to_s].each { |f| require f }
@@ -0,0 +1,20 @@
1
+ shared_context 'database setup' do
2
+ let(:configuration) do
3
+ ROM::Configuration.new(
4
+ default: [:csv, path],
5
+ users: [:csv, path],
6
+ addresses: [:csv, addresses_path],
7
+ utf8: [:csv, users_with_utf8_path, { encoding: 'iso-8859-2', col_sep: ';' }]
8
+ ).use(:macros)
9
+ end
10
+ let(:container) { ROM.container(configuration) }
11
+
12
+ let(:original_path) { File.expand_path('./spec/fixtures/users.csv') }
13
+ let(:path) { File.expand_path('./spec/fixtures/testing.csv') }
14
+ let(:addresses_path) { File.expand_path('./spec/fixtures/addresses.csv') }
15
+ let(:users_with_utf8_path) { File.expand_path('./spec/fixtures/users.utf-8.csv') }
16
+
17
+ before do
18
+ FileUtils.copy(original_path, path)
19
+ end
20
+ 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.2.0
4
+ version: 0.3.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-08-19 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rom
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.9'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.9.0
19
+ version: '1.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.9'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.9.0
26
+ version: '1.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +108,7 @@ files:
114
108
  - spec/integration/relation_spec.rb
115
109
  - spec/integration/repository_spec.rb
116
110
  - spec/spec_helper.rb
111
+ - spec/support/database_setup.rb
117
112
  - spec/unit/dataset_spec.rb
118
113
  - spec/unit/repository_spec.rb
119
114
  homepage: http://rom-rb.org
@@ -136,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
131
  version: '0'
137
132
  requirements: []
138
133
  rubyforge_project:
139
- rubygems_version: 2.4.5
134
+ rubygems_version: 2.5.1
140
135
  signing_key:
141
136
  specification_version: 4
142
137
  summary: CSV support for Ruby Object Mapper
@@ -150,5 +145,6 @@ test_files:
150
145
  - spec/integration/relation_spec.rb
151
146
  - spec/integration/repository_spec.rb
152
147
  - spec/spec_helper.rb
148
+ - spec/support/database_setup.rb
153
149
  - spec/unit/dataset_spec.rb
154
150
  - spec/unit/repository_spec.rb