aptly-api 0.3.0 → 0.4.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: 626177bba4926b1d4edfe1229e5e334238cf61b4
4
- data.tar.gz: 077010652f6d2059f85e647f89913ddbfcd23daa
3
+ metadata.gz: 4780f4046bb039881a21ccaf84875a3a1ace1b13
4
+ data.tar.gz: 930424d21df245e34f9748995bba0b54422b924e
5
5
  SHA512:
6
- metadata.gz: c9d07b75e5ba858305bf41f4e274db6c22a5a00f7f404dfd32b746cd5e91ae3abe41f20199a37481f3540f68091f9a10c65360dd16734a793495ff6e5d0d4b28
7
- data.tar.gz: 9feb9b78522009ffbc8d980835d6a2b8165157cbf9e3c697ea5f6ec732a97e0d7e22c52918b052fa1b36b90084e8fa4eb33d564be80118243f206dc8fe7d9347
6
+ metadata.gz: cbe5dc685508f22ec9bd6fbe4d9557ebd2fbcf4e12e43a7eb6c5cd04e85f80b7f62ef2194a1c2ece5507a6621dfa9179adeee9fcf034882dd6fdf59486d23298
7
+ data.tar.gz: ee604d080ccb11341dd95bac7b43cd9c25686d9bb640e80772e80e4442a3b1c1d02101090cdfba731b76d1ce3a0714e7d34508be6028d2bc9826dc44e853d02a
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.1
3
+
data/aptly-api.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rake', '~> 11.0'
26
26
  spec.add_development_dependency 'rake-notes', '~> 0.2'
27
27
  spec.add_development_dependency 'simplecov', '~> 0.11'
28
- spec.add_development_dependency 'webmock', '~> 1.22'
28
+ spec.add_development_dependency 'webmock', '~> 2.1'
29
29
  spec.add_development_dependency 'yard', '~> 0.8'
30
30
 
31
31
  spec.add_dependency 'faraday', '~> 0.9'
@@ -26,7 +26,7 @@ module Aptly
26
26
  @query = kwords.fetch(:query, DEFAULT_QUERY)
27
27
 
28
28
  uri = ::Aptly.configuration.uri
29
- @connection = Faraday.new(url: uri.to_s) do |c|
29
+ @connection = Faraday.new(uri.to_s) do |c|
30
30
  c.request :multipart
31
31
  c.request :url_encoded
32
32
  c.adapter :net_http
data/lib/aptly/errors.rb CHANGED
@@ -19,6 +19,9 @@ module Aptly
19
19
  # Raised when a request returns code 500.
20
20
  class ServerError < HTTPError; end
21
21
 
22
+ # Raised when a Snapshot consists of a unknown source type
23
+ class UnknownSourceTypeError < StandardError; end
24
+
22
25
  # Raised when a file operation had an error.
23
26
  class RepositoryFileError < StandardError
24
27
  # @!attribute [r] failures
data/lib/aptly/publish.rb CHANGED
@@ -8,7 +8,7 @@ module Aptly
8
8
  class PublishedRepository < Representation
9
9
  def initialize(*args)
10
10
  super(*args)
11
- self.Sources.collect! { |s| Repository.new(connection, s) }
11
+ parse_sources
12
12
  end
13
13
 
14
14
  # Drops a published repository. This removes the published repository
@@ -51,5 +51,18 @@ module Aptly
51
51
  def api_prefix
52
52
  self.Prefix.tr('_', '__').tr('/', '_')
53
53
  end
54
+
55
+ def parse_sources
56
+ self.Sources.collect! do |s|
57
+ case self.SourceKind
58
+ when 'local'
59
+ Repository.new(connection, s)
60
+ when 'snapshot'
61
+ Snapshot.new(connection, s)
62
+ else
63
+ raise Aptly::Errors::UnknownSourceTypeError
64
+ end
65
+ end
66
+ end
54
67
  end
55
68
  end
@@ -0,0 +1,26 @@
1
+ module Aptly
2
+ module Publishable
3
+ # Lists all PublishedRepositories self is published in. Namely self must
4
+ # be a source of the published repository in order for it to appear here.
5
+ # This method always returns an array of affected published repositories.
6
+ # If you use this method with a block it will additionally yield each
7
+ # published repository that would appear in the array, making it a shorthand
8
+ # for {Array#each}.
9
+ # @yieldparam pub [PublishedRepository]
10
+ # @return [Array<PublishedRepository>]
11
+ def published_in
12
+ Aptly::PublishedRepository.list(connection).select do |pub|
13
+ next false unless pub.Sources.any? do |src|
14
+ src.Name == self.Name
15
+ end
16
+ yield pub if block_given?
17
+ true
18
+ end
19
+ end
20
+
21
+ # @return [Boolean]
22
+ def published?
23
+ !published_in.empty?
24
+ end
25
+ end
26
+ end
@@ -4,11 +4,14 @@ require 'tmpdir'
4
4
  require_relative 'errors'
5
5
  require_relative 'representation'
6
6
  require_relative 'snapshot'
7
+ require_relative 'publishable'
7
8
 
8
9
  module Aptly
9
10
  # Aptly repository representation.
10
11
  # @see http://www.aptly.info/doc/api/repos/
11
12
  class Repository < Representation
13
+ include Publishable
14
+
12
15
  # Delete this repository.
13
16
  def delete(**kwords)
14
17
  connection.send(:delete, "/repos/#{self.Name}", query: kwords)
@@ -78,29 +81,6 @@ module Aptly
78
81
  Aptly.publish([{ Name: self.Name }], prefix, 'local', kwords)
79
82
  end
80
83
 
81
- # @return [Boolean]
82
- def published?
83
- !published_in.empty?
84
- end
85
-
86
- # Lists all PublishedRepositories self is published in. Namely self must
87
- # be a source of the published repository in order for it to appear here.
88
- # This method always returns an array of affected published repositories.
89
- # If you use this method with a block it will additionally yield each
90
- # published repository that would appear in the array, making it a shorthand
91
- # for {Array#each}.
92
- # @yieldparam pub [PublishedRepository]
93
- # @return [Array<PublishedRepository>]
94
- def published_in
95
- Aptly::PublishedRepository.list(connection).select do |pub|
96
- next false unless pub.Sources.any? do |src|
97
- src.Name == self.Name
98
- end
99
- yield pub if block_given?
100
- true
101
- end
102
- end
103
-
104
84
  # Edit this repository's attributes as per the parameters.
105
85
  # @note this possibly mutates the attributes depending on the HTTP response
106
86
  # @return [self] if the instance data was mutated
@@ -116,9 +96,16 @@ module Aptly
116
96
  end
117
97
 
118
98
  # Creates a new {Snapshot}
99
+ # @param name [String] name of snapshot
119
100
  # @return {Snapshot} newly created instance
120
- def snapshot(**kwords)
121
- kwords = kwords.map { |k, v| [k.to_s.capitalize, v] }.to_h
101
+ def snapshot(name = nil, **kwords)
102
+ # TODO: 1.0
103
+ if name.nil? && !kwords.key?(:Name)
104
+ # backwards compatible handling allows name to be passed though
105
+ # kwords or the argument. Argument is preferred.
106
+ raise ArgumentError, 'wrong number of arguments (given 0, expected 1)'
107
+ end
108
+ kwords[:Name] = name unless name.nil?
122
109
  response = connection.send(:post, "/repos/#{self.Name}/snapshots",
123
110
  body: JSON.generate(kwords))
124
111
  Aptly::Snapshot.new(::Aptly::Connection.new, JSON.parse(response.body))
@@ -1,9 +1,12 @@
1
1
  require_relative 'representation'
2
+ require_relative 'publishable'
2
3
 
3
4
  module Aptly
4
5
  # Aptly snapshots representation.
5
6
  # @see http://www.aptly.info/doc/api/snapshots/
6
7
  class Snapshot < Representation
8
+ include Publishable
9
+
7
10
  # Updates this snapshot
8
11
  # @return [self] if the instance data was mutated
9
12
  # @return [nil] if the instance data was not mutated
@@ -50,7 +53,6 @@ module Aptly
50
53
  Aptly.publish([{ Name: self.Name }], prefix, 'snapshot', kwords)
51
54
  end
52
55
 
53
-
54
56
  class << self
55
57
  # List all known snapshots.
56
58
  # @param connection [Connection] connection to use for the instance
data/lib/aptly/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # Aptly API
2
2
  module Aptly
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.4.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptly-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harald Sitter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.22'
103
+ version: '2.1'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.22'
110
+ version: '2.1'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: yard
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +144,7 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".gitignore"
147
+ - ".rubocop.yml"
147
148
  - ".travis.yml"
148
149
  - CODE_OF_CONDUCT.md
149
150
  - COPYING.lib
@@ -160,6 +161,7 @@ files:
160
161
  - lib/aptly/errors.rb
161
162
  - lib/aptly/files.rb
162
163
  - lib/aptly/publish.rb
164
+ - lib/aptly/publishable.rb
163
165
  - lib/aptly/repository.rb
164
166
  - lib/aptly/representation.rb
165
167
  - lib/aptly/snapshot.rb