ruby_tfs 0.0.2 → 0.0.3

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.
data/lib/tfs/builds.rb CHANGED
@@ -23,8 +23,8 @@ module TFS
23
23
  #
24
24
  def find(definition, project, number)
25
25
  begin
26
- TFS.builds("Definition='#{definition}',Project='#{project}',Number='#{number}'").run.first
27
- rescue RestClient::BadRequest => e
26
+ TFS.builds(definition: definition, project: project, number: number).run.first
27
+ rescue RestClient::ResourceNotFound => e
28
28
  raise Queryable::RecordNotFound, "No record found for '#{definition}', '#{project}', #{number}"
29
29
  end
30
30
  end
@@ -0,0 +1,19 @@
1
+ module TFS
2
+ class Changes < Queryable
3
+
4
+ class << self
5
+ # Changes have to be scoped by changesets, so all requires we have a changeset id
6
+ def all(changeset)
7
+ TFS.changesets(changeset).changes
8
+ end
9
+
10
+ # Change can be found by changeset and path
11
+ #
12
+ # TFS::Changes.find(123, '/path/to/change')
13
+ #
14
+ def find(changeset, path)
15
+ TFS.changes({changeset: changeset, path: path}).run.first
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,9 @@
1
+ require 'tfs/changes'
2
+
1
3
  module TFS
2
4
  class Changesets < Queryable
5
+ add_child TFS::Changes
6
+
3
7
  class << self
4
8
  # Changeset can be found by id alone
5
9
  #
data/lib/tfs/client.rb CHANGED
@@ -23,10 +23,10 @@ module TFS
23
23
 
24
24
  # Creates the connection to the data provider source
25
25
  def connect
26
- @connection = @provider.new endpoint, opts_for_connection
26
+ @connection ||= @provider.new endpoint, opts_for_connection
27
27
  end
28
28
 
29
- [TFS::Builds, TFS::Changesets, TFS::Projects, TFS::WorkItems].each do |klass|
29
+ TFS::QueryEngine::VALID_CLASSES.each do |klass|
30
30
  define_method(base_class(klass).downcase) do |*params|
31
31
  TFS::QueryEngine.new(klass, @connection, params)
32
32
  end
@@ -1,6 +1,7 @@
1
1
  require 'tfs/queryable'
2
2
  require 'tfs/builds'
3
3
  require 'tfs/changesets'
4
+ require 'tfs/changes'
4
5
  require 'tfs/projects'
5
6
 
6
7
  require 'tfs/work_items'
@@ -12,15 +13,25 @@ module TFS
12
13
 
13
14
  attr_reader :type
14
15
 
16
+
17
+ # Classes we currently support queries on
15
18
  VALID_CLASSES = [
16
19
  TFS::Builds,
17
20
  TFS::Changesets,
18
21
  TFS::Projects,
19
- TFS::WorkItems
22
+ TFS::WorkItems,
23
+ TFS::Changes
20
24
  ]
21
25
 
26
+ # Default pagination `#all` limit
27
+ # for all other actions, it limits by default to 20 (API level limit)
22
28
  DEFAULT_LIMIT = 50
23
29
 
30
+ # A new query requres a base class (of one of the above `VALID_CLASSES`),
31
+ # a connection (from `client.connection`) and can take additional selection parameters
32
+ #
33
+ # TFS::QueryEngine(TFS::Projects, TFS.client.connection, 'project-name')
34
+ #
24
35
  def initialize(for_class, connection, params="")
25
36
  check_type(for_class)
26
37
  @type, @connection = for_class, connection
@@ -28,45 +39,48 @@ module TFS
28
39
  @native_query = @connection.send(base_class(for_class), normalize(params))
29
40
  end
30
41
 
42
+ # Returns the underlying `OData::QueryBuilder` object in case you want to work
43
+ # directly against the odata adapter
31
44
  def raw
32
45
  @native_query
33
46
  end
34
47
 
48
+ # Limit records returned
35
49
  def limit(count)
36
50
  @native_query = @native_query.top(count)
37
51
  self
38
52
  end
39
53
 
54
+ # Ordering. Must be a valid field
40
55
  def order_by(query)
41
56
  @native_query = @native_query.order_by(query)
42
57
  self
43
58
  end
44
59
 
60
+ # Filtering, use odata query syntax
45
61
  def where(filter)
46
62
  @native_query = @native_query.filter(filter)
47
63
  self
48
64
  end
49
65
 
66
+ # Return a count of records rather than records
50
67
  def count
51
68
  @native_query = @native_query.count
52
69
  self
53
70
  end
54
71
 
55
- def include(klass)
56
- check_type(klass)
57
- @native_query.expand(base_class(klass))
58
- self
59
- end
60
-
72
+ # For pagination. Skips supplied number of records
61
73
  def page(start)
62
74
  @native_query = @native_query.skip(start)
63
75
  self
64
76
  end
65
77
 
78
+ # Required to execute the query
66
79
  def run
67
80
  @connection.execute
68
81
  end
69
82
 
83
+ # Returns the actual query string (does not run query)
70
84
  def to_query
71
85
  @native_query.query
72
86
  end
data/ruby_tfs.gemspec CHANGED
@@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.required_rubygems_version = '>= 1.3.6'
20
20
  spec.summary = spec.description
21
21
  spec.test_files = Dir.glob("spec/**/*")
22
- spec.version = "0.0.2"
22
+ spec.version = "0.0.3"
23
23
  end
@@ -448,4 +448,50 @@ http_interactions:
448
448
  syntax.</message>\r\n</error>"
449
449
  http_version:
450
450
  recorded_at: Wed, 06 Mar 2013 21:02:55 GMT
451
+ - request:
452
+ method: get
453
+ uri: https://snd%5Cplukevdh_cp:garbage@codeplexodata.cloudapp.net/TFS29/Builds(Definition='rubytfs_demo',Project='rubytfs',Number='1')
454
+ body:
455
+ encoding: US-ASCII
456
+ string: ''
457
+ headers:
458
+ Accept:
459
+ - ! '*/*; q=0.5, application/xml'
460
+ Accept-Encoding:
461
+ - gzip, deflate
462
+ User-Agent:
463
+ - Ruby
464
+ response:
465
+ status:
466
+ code: 404
467
+ message: Not Found
468
+ headers:
469
+ Cache-Control:
470
+ - private
471
+ Content-Length:
472
+ - '246'
473
+ Content-Type:
474
+ - application/xml
475
+ Expires:
476
+ - Wed, 06 Mar 2013 22:06:55 GMT
477
+ Vary:
478
+ - ! '*'
479
+ Server:
480
+ - Microsoft-IIS/7.0
481
+ Dataserviceversion:
482
+ - 1.0;
483
+ X-Aspnet-Version:
484
+ - 4.0.30319
485
+ X-Powered-By:
486
+ - ASP.NET
487
+ Date:
488
+ - Wed, 06 Mar 2013 22:06:34 GMT
489
+ body:
490
+ encoding: US-ASCII
491
+ string: ! "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\r\n<error
492
+ xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\r\n
493
+ \ <code></code>\r\n <message xml:lang=\"en-US\">Resource not found for the
494
+ segment 'Builds'.</message>\r\n</error>"
495
+ http_version:
496
+ recorded_at: Wed, 06 Mar 2013 22:06:34 GMT
451
497
  recorded_with: VCR 2.4.0
@@ -25,18 +25,6 @@ describe TFS::QueryEngine do
25
25
  query.limit(10).order_by("Reason")
26
26
  end
27
27
 
28
- it "can include other results" do
29
- native_query.should_receive(:expand).with('Changesets').and_return(native_query).once
30
-
31
- query.include(TFS::Changesets)
32
- end
33
-
34
- it "raises error if expand by invalid class" do
35
- expect { query.include('String') }.to raise_error(TypeError)
36
-
37
- native_query.should_not have_received(:expand)
38
- end
39
-
40
28
  it "can cause pagination" do
41
29
  native_query.should_receive(:skip).with(10)
42
30
  query.page(10)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_tfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -55,6 +55,7 @@ files:
55
55
  - README.md
56
56
  - ruby_tfs.gemspec
57
57
  - lib/tfs/builds.rb
58
+ - lib/tfs/changes.rb
58
59
  - lib/tfs/changesets.rb
59
60
  - lib/tfs/class_helpers.rb
60
61
  - lib/tfs/client.rb
@@ -95,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
96
  version: '0'
96
97
  segments:
97
98
  - 0
98
- hash: 1497286173893304256
99
+ hash: -1238616650401436106
99
100
  required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  none: false
101
102
  requirements: