rom-git 1.0.0 → 2.0.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: 111cf1f0241af1ad9f5b154cb1d81f2d79fdef5a
4
- data.tar.gz: 07a83b21d7665f71a08436aa440631aeb1fd87ff
3
+ metadata.gz: 9127df6dee3e69958709ed95a7d8324c4d64d3ec
4
+ data.tar.gz: 4f6d9a43f647b2f297cd77c79b4ce3bdbb24fea5
5
5
  SHA512:
6
- metadata.gz: 7e98545766f30e46127a5dfbdce642cc80b6e1f6db32224fba2e97fbbe76fc48bb93393cf48ce3bc5307a48ed019ab8647feea5fd36afec32d4da14ae5444f2f
7
- data.tar.gz: a07f1b6b18a6551b4873ff745d0b55d25a61701828591577be0afd50686b66d1ed65db1441b504a81a71a23176c18c4880a990f7a8db9305a6bfd32b3c13da08
6
+ metadata.gz: 7baa254bcca878d54345fa88259ce3a462fbd2e6ef15cff8ec58779bc911e8433cad61b27528729a05b8a4f607b636eb01f7c6c293a476d0a1769e1bf444dc9f
7
+ data.tar.gz: b7975580bbbb61672c1e00a97b93641500f3ca2ce0508c181241d3b321f985d148458b7847e76fe8cffa5e756f7a9fe8863fb0d07b0e9443e78c2e9b9e65a1e9
@@ -1,3 +1,10 @@
1
- # v1.0.0 (Unreleased)
1
+ # v2.0.0
2
+
3
+ ## BREAKING CHANGE
4
+
5
+ * Use ROM's new Relation/Gateway API
6
+ * Restrict rom-git to ROM v0.8.x
7
+
8
+ # v1.0.0
2
9
 
3
10
  * Initial release
data/Gemfile CHANGED
@@ -1,2 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
+
4
+ group :test do
5
+ gem 'inflecto'
6
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ROM::Git [![Travis](https://secure.travis-ci.org/franckverrot/rom-git.png)](http://travis-ci.org/franckverrot/rom-git)
1
+ # ROM::Git [![Travis](https://secure.travis-ci.org/rom-rb/rom-git.png)](http://travis-ci.org/rom-rb/rom-git)
2
2
  Minimal Git support for [Ruby Object Mapper](https://github.com/rom-rb/rom).
3
3
  Currently only supports reading from the repository.
4
4
 
@@ -1,4 +1,7 @@
1
1
  require "rugged"
2
2
 
3
- require "rom"
4
- require "rom/git/adapter"
3
+ require 'rom'
4
+ require 'rom/git/gateway'
5
+ require 'rom/git/relation'
6
+
7
+ ROM.register_adapter(:git, ROM::Git)
@@ -0,0 +1,29 @@
1
+ require 'rom/memory/dataset'
2
+
3
+ module ROM
4
+ module Git
5
+ class Dataset < ROM::Memory::Dataset
6
+ option :path, reader: true
7
+ option :options, reader: true
8
+ option :gateway, reader: true
9
+
10
+ def self.row_proc
11
+ lambda do |row|
12
+ {
13
+ sha1: row[:id_new] || row[:sha1],
14
+ message: row[:message],
15
+ committer: (row[:committer].fetch(:name, 'unknown committer name') rescue row[:committer].to_s)
16
+ }
17
+ end
18
+ end
19
+
20
+ def reload!
21
+ @data = gateway.reset_data
22
+ end
23
+
24
+ def count
25
+ @data.count
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ require 'rom/gateway'
2
+ require 'rom/git/dataset'
3
+
4
+ module ROM
5
+ module Git
6
+ class Gateway < ROM::Gateway
7
+ def initialize(path, options = {})
8
+ super()
9
+ @path = path
10
+ @options = options
11
+ @datasets = {}
12
+ reset_data
13
+ end
14
+
15
+ def [](name)
16
+ @datasets[name]
17
+ end
18
+
19
+ def dataset(name)
20
+ @datasets[name] = Dataset.new(@connection, path: @path, options: @options, gateway: self)
21
+ end
22
+
23
+ def dataset?(name)
24
+ @datasets.key?(name)
25
+ end
26
+
27
+ def reset_data
28
+ repo = Rugged::Repository.new(@path)
29
+ walker = Rugged::Walker.new(repo)
30
+ branch = (@options || {}).fetch(:branch, 'refs/head/master')
31
+ ref = repo.references[branch]
32
+
33
+ @connection = ref.log rescue []
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ require 'rom/relation'
2
+
3
+ module ROM
4
+ module Git
5
+ class Relation < ROM::Relation
6
+ adapter :git
7
+
8
+ forward :join, :project, :restrict, :order
9
+
10
+ def count
11
+ dataset.count
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rom-git"
5
- spec.version = "1.0.0"
5
+ spec.version = "2.0.0"
6
6
  spec.authors = ["Franck Verrot"]
7
7
  spec.email = ["franck@verrot.fr"]
8
8
  spec.summary = "Git support for the ROM Ruby Object Mapper"
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
15
  spec.test_files = spec.files.grep(%r{^test/})
16
16
 
17
- spec.add_runtime_dependency "rom", "~> 0.5", ">= 0.5.0"
17
+ spec.add_runtime_dependency "rom", "~> 0.8.0"
18
18
 
19
19
  spec.add_dependency "rugged"
20
20
 
@@ -22,5 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "minitest"
24
24
  spec.add_development_dependency "pry"
25
- spec.add_development_dependency "anima"
25
+ spec.add_development_dependency "inflecto"
26
+ spec.add_development_dependency "virtus"
26
27
  end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+ require 'virtus'
3
+
4
+ describe 'Git gateway' do
5
+ describe 'using the default (master) branch' do
6
+ let(:path) { File.expand_path('./test/fixtures') }
7
+ let(:rom_setup) do
8
+ ROM.setup(
9
+ commits: [
10
+ :git,
11
+ path,
12
+ branch: 'refs/heads/master'
13
+ ]
14
+ )
15
+ end
16
+ let(:rom) { rom_setup.finalize }
17
+
18
+ before do
19
+ rom_setup.relation(:commits) do
20
+ gateway :commits
21
+
22
+ def by_sha1(sha1)
23
+ restrict(sha1: sha1)
24
+ end
25
+
26
+ def by_committer(committer_name)
27
+ restrict(committer: committer_name)
28
+ end
29
+ end
30
+
31
+ rom_setup.mappers do
32
+ define(:commits) do
33
+ model(Class.new do
34
+ include Virtus.model
35
+
36
+ attribute :sha1, String
37
+ attribute :message, String
38
+ attribute :committer, String
39
+ end)
40
+
41
+ register_as :entity
42
+ end
43
+ end
44
+ end
45
+
46
+ describe 'env#relation' do
47
+ it 'returns restricted and mapped object' do
48
+ commit = rom.relation(:commits).as(:entity).by_sha1('101868c4ce62b7e96a1f7c3b64fa40285ee00d5e').to_a.first
49
+
50
+ assert_equal '101868c4ce62b7e96a1f7c3b64fa40285ee00d5e', commit.sha1
51
+ assert_equal 'commit (initial): Initial commit', commit.message
52
+ assert_equal 'Franck Verrot', commit.committer
53
+ end
54
+ end
55
+
56
+ # describe 'with a custom branch'
57
+ end
58
+ end
@@ -0,0 +1,31 @@
1
+ require "test_helper"
2
+
3
+ describe "Git Gateway" do
4
+ let(:path) { File.expand_path("./test/fixtures") }
5
+ let(:rom_setup) do
6
+ ROM.setup(
7
+ commits: [
8
+ :git,
9
+ path,
10
+ branch: 'refs/heads/master'
11
+ ]
12
+ )
13
+ end
14
+
15
+ before do
16
+ ROM.plugins do
17
+ adapter :git do
18
+ register :test_plugin, Module.new, type: :relation
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "relation with plugin" do
24
+ it "shouldn't raise error" do
25
+ rom_setup.relation(:commits) do
26
+ gateway :commits
27
+ use :test_plugin
28
+ end
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck Verrot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-08-03 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.5'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.5.0
19
+ version: 0.8.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.5'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.5.0
26
+ version: 0.8.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rugged
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -101,7 +95,21 @@ dependencies:
101
95
  - !ruby/object:Gem::Version
102
96
  version: '0'
103
97
  - !ruby/object:Gem::Dependency
104
- name: anima
98
+ name: inflecto
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: virtus
105
113
  requirement: !ruby/object:Gem::Requirement
106
114
  requirements:
107
115
  - - ">="
@@ -130,7 +138,9 @@ files:
130
138
  - Rakefile
131
139
  - lib/rom-git.rb
132
140
  - lib/rom/git.rb
133
- - lib/rom/git/adapter.rb
141
+ - lib/rom/git/dataset.rb
142
+ - lib/rom/git/gateway.rb
143
+ - lib/rom/git/relation.rb
134
144
  - rom-git.gemspec
135
145
  - test/fixtures/HEAD
136
146
  - test/fixtures/logs/HEAD
@@ -147,7 +157,8 @@ files:
147
157
  - test/fixtures/objects/f0/184ad83045ea3a7e32fb547d5275f21686558d
148
158
  - test/fixtures/objects/fe/326fd5cb986e6ef3d83f02857fb5bc10333aa4
149
159
  - test/fixtures/refs/heads/master
150
- - test/integration/adapter_test.rb
160
+ - test/integration/gateway_test.rb
161
+ - test/integration/relation_test.rb
151
162
  - test/test_helper.rb
152
163
  homepage: https://github.com/franckverrot/rom-git
153
164
  licenses:
@@ -169,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
180
  version: '0'
170
181
  requirements: []
171
182
  rubyforge_project:
172
- rubygems_version: 2.4.4
183
+ rubygems_version: 2.4.6
173
184
  signing_key:
174
185
  specification_version: 4
175
186
  summary: Git support for the ROM Ruby Object Mapper
@@ -189,5 +200,7 @@ test_files:
189
200
  - test/fixtures/objects/f0/184ad83045ea3a7e32fb547d5275f21686558d
190
201
  - test/fixtures/objects/fe/326fd5cb986e6ef3d83f02857fb5bc10333aa4
191
202
  - test/fixtures/refs/heads/master
192
- - test/integration/adapter_test.rb
203
+ - test/integration/gateway_test.rb
204
+ - test/integration/relation_test.rb
193
205
  - test/test_helper.rb
206
+ has_rdoc:
@@ -1,49 +0,0 @@
1
- module ROM
2
- module Git
3
- class Adapter < ROM::Adapter
4
- def self.schemes
5
- [:git]
6
- end
7
-
8
- class Dataset
9
- include Charlatan.new(:rows)
10
- include Enumerable
11
-
12
- def each
13
- rows.each do |row|
14
- res = {
15
- sha1: row[:id_new],
16
- message: row[:message],
17
- committer: row[:committer].fetch(:name, 'Unknown committer name')
18
- }
19
- yield(res)
20
- end
21
- end
22
- end
23
-
24
- # Expect a path to a single csv file which will be registered by
25
- # rom to the given name or :default as the repository.
26
- def initialize(*args)
27
- super
28
- repo = Rugged::Repository.new(uri.path)
29
- walker = Rugged::Walker.new(repo)
30
- branch = (@options || {}).fetch(:branch, 'refs/head/master')
31
- ref = repo.references[branch]
32
-
33
- @connection = ref.log rescue []
34
- end
35
-
36
- def [](_name)
37
- connection
38
- end
39
-
40
- def dataset(_name, _header)
41
- Dataset.new(connection)
42
- end
43
-
44
- def dataset?(_name)
45
- connection
46
- end
47
- end
48
- end
49
- end
@@ -1,71 +0,0 @@
1
- require "test_helper"
2
- require "anima"
3
-
4
-
5
- describe "Git Adapter" do
6
- let(:path) { File.expand_path("./test/fixtures") }
7
-
8
- def setup
9
- setup = ROM.setup("git://#{path}", branch: 'refs/heads/master')
10
-
11
- setup.schema do
12
- base_relation(:commits) do
13
- repository :default
14
-
15
- attribute "sha1"
16
- attribute "message"
17
- attribute "committer"
18
- end
19
- end
20
-
21
- setup.relation(:commits) do
22
- def by_committer(committer_name)
23
- find_all { |row| row[:committer] == committer_name }
24
- end
25
-
26
- def find_commit(sha1)
27
- find_all { |row| row[:sha1] == sha1 }
28
- end
29
- end
30
-
31
-
32
- setup.mappers do
33
- define(:commits) do
34
- model (Class.new do
35
- include Anima.new(:sha1, :message, :committer)
36
- end)
37
- end
38
- end
39
- setup
40
- end
41
-
42
- subject { s = setup; s.finalize }
43
-
44
- describe "env#read" do
45
- it "returns mapped object" do
46
- commit = subject.read(:commits).by_committer("Franck Verrot").to_a.first
47
-
48
- assert_equal '101868c4ce62b7e96a1f7c3b64fa40285ee00d5e', commit.sha1
49
- assert_equal 'commit (initial): Initial commit', commit.message
50
- assert_equal 'Franck Verrot', commit.committer
51
- end
52
- end
53
-
54
- describe "dataset#header" do
55
- it "returns the header defined in the schema" do
56
- assert_equal %w(sha1 message committer), subject.relations.commits.header
57
- end
58
- end
59
-
60
- describe "relation" do
61
- it "finds a specific commit by its sha1" do
62
- sha1 = 'fe326fd5cb986e6ef3d83f02857fb5bc10333aa4'
63
-
64
- commit = subject.read(:commits).find_commit(sha1).to_a.first
65
-
66
- assert_equal sha1, commit.sha1
67
- assert_equal 'commit: Add bar', commit.message
68
- assert_equal 'Franck Verrot', commit.committer
69
- end
70
- end
71
- end