pdc 0.1.11 → 0.1.12

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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +23 -0
  3. data/.travis.yml +3 -4
  4. data/Gemfile +0 -1
  5. data/docs/sphinx_deployment.mk +1 -1
  6. data/examples/local_pdc_dev.rb +10 -1
  7. data/examples/logger.rb +7 -14
  8. data/examples/pdc_global_component_contact.rb +18 -0
  9. data/examples/pdc_release_rpm_mapping.rb +2 -2
  10. data/examples/pdc_resource_tests.rb +3 -3
  11. data/examples/pdc_test_cache.rb +1 -1
  12. data/examples/prod_failures.rb +1 -1
  13. data/examples/prod_pdc.rb +10 -1
  14. data/examples/test_no_ssl_verification.rb +1 -1
  15. data/examples/url.rb +4 -4
  16. data/lib/pdc.rb +1 -1
  17. data/lib/pdc/base.rb +1 -0
  18. data/lib/pdc/config.rb +0 -7
  19. data/lib/pdc/http/request/token_fetcher.rb +1 -1
  20. data/lib/pdc/http/response/pagination.rb +0 -2
  21. data/lib/pdc/resource.rb +1 -0
  22. data/lib/pdc/resource/associations.rb +39 -0
  23. data/lib/pdc/resource/associations/association.rb +21 -0
  24. data/lib/pdc/resource/associations/builder.rb +46 -0
  25. data/lib/pdc/resource/associations/has_many.rb +26 -0
  26. data/lib/pdc/resource/attributes.rb +13 -4
  27. data/lib/pdc/resource/identity.rb +1 -1
  28. data/lib/pdc/resource/relation.rb +5 -0
  29. data/lib/pdc/resource/relation/pagination.rb +4 -4
  30. data/lib/pdc/resource/rest_api.rb +1 -1
  31. data/lib/pdc/resource/scopes.rb +1 -1
  32. data/lib/pdc/v1.rb +4 -0
  33. data/lib/pdc/v1/global_component_contact.rb +5 -0
  34. data/lib/pdc/v1/multi_destination.rb +8 -0
  35. data/lib/pdc/v1/release.rb +3 -1
  36. data/lib/pdc/v1/release_variant.rb +6 -1
  37. data/lib/pdc/v1/released_file.rb +10 -0
  38. data/lib/pdc/v1/variant_cpe.rb +7 -0
  39. data/lib/pdc/version.rb +1 -1
  40. data/pdc.gemspec +8 -10
  41. data/spec/fixtures/vcr/_page_count_returns_total_count.yml +6 -6
  42. data/spec/fixtures/vcr/behaves_like_an_array.yml +141 -0
  43. data/spec/fixtures/vcr/brew_can_be_nil.yml +23 -14
  44. data/spec/fixtures/vcr/brew_may_be_present.yml +4 -2
  45. data/spec/fixtures/vcr/caches_multiple_response.yml +42 -36
  46. data/spec/fixtures/vcr/caches_response_with_a_query.yml +16 -16
  47. data/spec/fixtures/vcr/caches_response_with_multiple_query.yml +16 -16
  48. data/spec/fixtures/vcr/caches_response_without_query.yml +14 -14
  49. data/spec/fixtures/vcr/can_find_global_contact_by_component_name.yml +47 -0
  50. data/spec/fixtures/vcr/can_get_release_by_multi_product_version.yml +9 -9
  51. data/spec/fixtures/vcr/can_iterate_using_each.yml +8 -8
  52. data/spec/fixtures/vcr/content_delivery_repos_must_return_a_record.yml +2 -2
  53. data/spec/fixtures/vcr/cpe_returns_number.yml +44 -0
  54. data/spec/fixtures/vcr/cpe_works_with_where.yml +85 -0
  55. data/spec/fixtures/vcr/destination_returns_count.yml +44 -0
  56. data/spec/fixtures/vcr/destination_works_with_where.yml +44 -0
  57. data/spec/fixtures/vcr/fetches_variants_of_a_release.yml +20 -20
  58. data/spec/fixtures/vcr/find_on_has_many_association.yml +48 -0
  59. data/spec/fixtures/vcr/get_released_files_by_file_primary_key.yml +44 -0
  60. data/spec/fixtures/vcr/get_released_files_by_release_id.yml +44 -0
  61. data/spec/fixtures/vcr/has_many_association.yml +48 -0
  62. data/spec/fixtures/vcr/has_serveral_cdn_content_delivery_repos.yml +1 -1
  63. data/spec/fixtures/vcr/must_has_compose.yml +45 -1
  64. data/spec/fixtures/vcr/must_has_version__attributes.yml +2 -2
  65. data/spec/fixtures/vcr/must_return_number_of_resources.yml +62 -14
  66. data/spec/fixtures/vcr/preserves_the_filters.yml +2 -2
  67. data/spec/fixtures/vcr/returns_a_contact_email.yml +47 -0
  68. data/spec/fixtures/vcr/returns_a_gloabl_contact_id.yml +47 -0
  69. data/spec/fixtures/vcr/returns_a_mail_name.yml +47 -0
  70. data/spec/fixtures/vcr/returns_contact_for_component.yml +47 -0
  71. data/spec/fixtures/vcr/returns_contact_role.yml +48 -0
  72. data/spec/fixtures/vcr/returns_cpe.yml +88 -0
  73. data/spec/fixtures/vcr/returns_number_of_released_files.yml +48 -0
  74. data/spec/fixtures/vcr/returns_release_file_by_retrieve.yml +44 -0
  75. data/spec/fixtures/vcr/returns_resources_on_that_page.yml +2 -2
  76. data/spec/fixtures/vcr/returns_the_total_count_and_not_items_in_page.yml +6 -6
  77. data/spec/fixtures/vcr/returns_url_of_a_release.yml +2 -2
  78. data/spec/fixtures/vcr/returns_url_of_a_release_variant.yml +7 -7
  79. data/spec/fixtures/vcr/scopes_on_associations.yml +48 -0
  80. data/spec/fixtures/vcr/should_not_be_in_the_list_of_attributes.yml +4 -4
  81. data/spec/fixtures/vcr/works_with_where.yml +45 -1
  82. data/spec/pdc/resource/associations_spec.rb +111 -0
  83. data/spec/pdc/resource/attributes_spec.rb +30 -20
  84. data/spec/pdc/resource/cache_spec.rb +1 -1
  85. data/spec/pdc/resource/identity_spec.rb +10 -10
  86. data/spec/pdc/resource/path_spec.rb +1 -1
  87. data/spec/pdc/resource/relation_spec.rb +1 -1
  88. data/spec/pdc/v1/content_delivery_repo_spec.rb +6 -6
  89. data/spec/pdc/v1/global_component_contact_spec.rb +64 -0
  90. data/spec/pdc/v1/multi_destination_sepc.rb +27 -0
  91. data/spec/pdc/v1/release_spec.rb +10 -10
  92. data/spec/pdc/v1/release_variant_spec.rb +8 -0
  93. data/spec/pdc/v1/released_file_spec.rb +37 -0
  94. data/spec/pdc/v1/variant_cpe_spec.rb +29 -0
  95. data/spec/spec_helper.rb +1 -4
  96. data/spec/support/fixtures.rb +29 -2
  97. metadata +77 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca306779982cf263fec603670b09c872859555fe
4
- data.tar.gz: 4561b58710ca446ed9d37b87ee0f898775f8a914
3
+ metadata.gz: 9f51f89eae34983035f4768fee0475cb2bed9a2b
4
+ data.tar.gz: b304391d32258708648f2d623cbc630fef9ff424
5
5
  SHA512:
6
- metadata.gz: dcef5e6ff461dcdfb37cf030af975e09a04f7f59f8b3bae2063c4b887e5ed88294fa2b16b0a4103c725848d04411384ac651593f37a8d24563e5e2f2437e6c62
7
- data.tar.gz: d6e5e38ba1e9ccc09559a034778d553d2eaf8dcc355ed4d2f91777408a806c92b787e9c4d8c5f2d1687c3110109476241b3322c70e151d0f71247a3a312c8206
6
+ metadata.gz: 9f50d8c5d916bf243a1726602870730e52dc30495356b8b69295284bec9e45383cfe45441a6ac361a91252ff50710d55e26df691060bb6c51aa19838ec05b720
7
+ data.tar.gz: ecbfd3ac9df4b19f266c317ad52a0175a8813df97e93eb5440ce656c5a92dd0827ea2bd54a46cbf1707d85f3672241d0bd851e4850311a077e9b90debc86274d
@@ -1,6 +1,8 @@
1
1
  AllCops:
2
2
  DisplayCopNames: true
3
3
  DisplayStyleGuide: true
4
+ Exclude:
5
+ - bin/console
4
6
 
5
7
  Style/Documentation:
6
8
  Enabled: false
@@ -9,12 +11,33 @@ Style/ClassAndModuleChildren:
9
11
  Enabled: false
10
12
  EnforcedStyle: compact
11
13
 
14
+ Style/MethodMissing:
15
+ Exclude:
16
+ - lib/pdc/resource/per_thread_registry.rb
17
+
12
18
  Metrics/LineLength:
13
19
  Max: 100
20
+ Exclude:
21
+ - spec/**/*.rb
22
+ - examples/**/*.rb
14
23
 
15
24
  Metrics/MethodLength:
16
25
  Max: 25
17
26
 
18
27
  Metrics/AbcSize:
19
28
  Max: 25
29
+ Exclude:
30
+ - lib/pdc/config.rb
31
+
32
+ Metrics/BlockLength:
33
+ Max: 100
34
+ Exclude:
35
+ - spec/pdc/**/*.rb
36
+ - examples/**/*.rb
37
+
38
+ Naming/PredicateName:
39
+ Enabled: false
20
40
 
41
+ Metrics/ModuleLength:
42
+ Exclude:
43
+ - lib/pdc/config.rb
@@ -15,14 +15,13 @@ script:
15
15
  - bundle exec rake test
16
16
  - >
17
17
  if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
18
- bundle exec pronto run -f github_pr -c origin/${TRAVIS_BRANCH}
18
+ bundle exec rubocop
19
19
  fi
20
-
21
20
  after_success:
22
21
  - >
23
22
  [ "$TRAVIS_BRANCH" = "master" ] &&
24
- [ "$TRAVIS_PULL_REQUEST" = "false" ] &&
25
- make deploy_doc
23
+ [ "$TRAVIS_PULL_REQUEST" = "false" ]
24
+ make -C docs/ setup_gh_pages gen_deploy
26
25
  env:
27
26
  global:
28
27
  PRONTO_PULL_REQUEST_ID=${TRAVIS_PULL_REQUEST}
data/Gemfile CHANGED
@@ -20,7 +20,6 @@ group :test do
20
20
  gem 'minitest-focus'
21
21
  gem 'minitest-reporters', '~> 1.1.9'
22
22
  gem 'mocha'
23
- gem 'rack', '~> 1.4.7'
24
23
  gem 'simplecov'
25
24
  gem 'timecop'
26
25
  gem 'vcr'
@@ -62,7 +62,7 @@ endif
62
62
  #if REPO_URL_GITHUB was NOT defined by travis-ci
63
63
  ifndef REPO_URL_GITHUB
64
64
  # Configure your right github project repo
65
- # REPO_URL_GITHUB = https://github.com/product-definition-center/pdc-client
65
+ REPO_URL_GITHUB = https://github.com/product-definition-center/pdc-ruby-gem.git
66
66
  endif
67
67
 
68
68
  ## end deployment configuration, don't edit anything below this line ##
@@ -10,6 +10,15 @@ def main
10
10
 
11
11
  releases = PDC::V1::Release.all!.to_a
12
12
  ap releases
13
+
14
+ released_files = PDC::V1::ReleasedFile.all!.to_a
15
+ ap released_files
16
+
17
+ destinations = PDC::V1::MultiDestination.all!.to_a
18
+ ap destinations
19
+
20
+ cpes = PDC::V1::VariantCpe.all!.to_a
21
+ ap cpes
13
22
  end
14
23
 
15
- main if __FILE__ == $PROGRAM_NAME
24
+ main if $PROGRAM_NAME == __FILE__
@@ -5,20 +5,15 @@ require 'ap'
5
5
  class FakeLogger
6
6
  attr_accessor :level
7
7
 
8
- def debug(*args)
9
- end
8
+ def debug(*args) end
10
9
 
11
- def info(*args)
12
- end
10
+ def info(*args) end
13
11
 
14
- def warn(*args)
15
- end
12
+ def warn(*args) end
16
13
 
17
- def fatal(*args)
18
- end
14
+ def fatal(*args) end
19
15
 
20
- def error(*args)
21
- end
16
+ def error(*args) end
22
17
  end
23
18
 
24
19
  # PDC.logger = FakeLogger.new
@@ -39,11 +34,9 @@ path = 'a_non_existent_file'
39
34
 
40
35
  begin
41
36
  File.foreach(path) do |line|
42
- unless line =~ /^(\w+) = (.*)$/
43
- logger.error("Line in wrong format: #{line.chomp}")
44
- end
37
+ logger.error("Line in wrong format: #{line.chomp}") unless line =~ /^(\w+) = (.*)$/
45
38
  end
46
- rescue => err
39
+ rescue StandardError => err
47
40
  logger.fatal('Caught exception; exiting')
48
41
  logger.fatal(err)
49
42
  end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/pdc'
4
+
5
+ def main
6
+ PDC.configure do |config|
7
+ config.site = 'https://pdc.engineering.redhat.com'
8
+ config.log_level = :debug
9
+ config.disable_caching = true
10
+ end
11
+
12
+ comp_contact = PDC::V1::GlobalComponentContact.where(
13
+ component: 'vlgothic-fonts'
14
+ ).find_one!
15
+ puts comp_contact.contact
16
+ end
17
+
18
+ main if $PROGRAM_NAME == __FILE__
@@ -10,9 +10,9 @@ def main
10
10
  end
11
11
 
12
12
  mapping = PDC::V1::ReleaseRpmMapping.where(
13
- release_id: 'ceph-2.1-updates@rhel-7', package: 'ceph'
13
+ release_id: 'rhceph-2.1@rhel-7', package: 'ceph'
14
14
  ).first
15
15
  puts mapping.mapping
16
16
  end
17
17
 
18
- main if __FILE__ == $PROGRAM_NAME
18
+ main if $PROGRAM_NAME == __FILE__
@@ -5,7 +5,7 @@ WebMock.disable! # this uses real server
5
5
 
6
6
  #### service config ####
7
7
  def token
8
- script_path = File.expand_path(File.dirname(__FILE__))
8
+ script_path = File.expand_path(__dir__)
9
9
  token_path = File.join(script_path, '.token', 'pdc.prod')
10
10
  File.read(token_path).chomp.tap { |x| puts "Using token :#{x}" }
11
11
  rescue Errno::ENOENT => e
@@ -23,7 +23,7 @@ server = {
23
23
 
24
24
  prod: {
25
25
  site: 'https://pdc.engineering.redhat.com',
26
- token: ->() { token } # read token only if needed
26
+ token: -> { token } # read token only if needed
27
27
  }
28
28
  }
29
29
 
@@ -198,7 +198,7 @@ end
198
198
  describe PDC::V1::ReleaseRpmMapping do
199
199
  let(:mapping) do
200
200
  PDC::V1::ReleaseRpmMapping.where(
201
- release_id: 'ceph-2.1-updates@rhel-7',
201
+ release_id: 'rhceph-2.1@rhel-7',
202
202
  package: 'ceph'
203
203
  ).first
204
204
  end
@@ -46,4 +46,4 @@ def main
46
46
  end
47
47
  end
48
48
 
49
- main if __FILE__ == $PROGRAM_NAME
49
+ main if $PROGRAM_NAME == __FILE__
@@ -23,4 +23,4 @@ def main
23
23
  end
24
24
  end
25
25
 
26
- main if __FILE__ == $PROGRAM_NAME
26
+ main if $PROGRAM_NAME == __FILE__
@@ -9,6 +9,15 @@ def main
9
9
 
10
10
  releases = PDC::V1::Release.all!.to_a
11
11
  ap releases
12
+
13
+ released_files = PDC::V1::ReleasedFile.all!.to_a
14
+ ap released_files
15
+
16
+ destinations = PDC::V1::MultiDestination.all!.to_a
17
+ ap destinations
18
+
19
+ cpes = PDC::V1::VariantCpe.all!.to_a
20
+ ap cpes
12
21
  end
13
22
 
14
- main if __FILE__ == $PROGRAM_NAME
23
+ main if $PROGRAM_NAME == __FILE__
@@ -13,4 +13,4 @@ def main
13
13
  puts "Release count: #{PDC::V1::Release.count}"
14
14
  end
15
15
 
16
- main if __FILE__ == $PROGRAM_NAME
16
+ main if $PROGRAM_NAME == __FILE__
@@ -7,11 +7,11 @@ PDC.configure do |config|
7
7
  end
8
8
 
9
9
  def main
10
- rhel7_1 = PDC::V1::Release.find('rhel-7.1')
11
- puts "release url : #{rhel7_1.url}"
12
- rhel7_1.variants.all.each do |v|
10
+ rhel71 = PDC::V1::Release.find('rhel-7.1')
11
+ puts "release url : #{rhel71.url}"
12
+ rhel71.variants.all.each do |v|
13
13
  puts "release variant url : #{v.url}"
14
14
  end
15
15
  end
16
16
 
17
- main if __FILE__ == $PROGRAM_NAME
17
+ main if $PROGRAM_NAME == __FILE__
data/lib/pdc.rb CHANGED
@@ -1,4 +1,4 @@
1
- $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
1
+ $LOAD_PATH << File.expand_path(__dir__)
2
2
 
3
3
  module PDC
4
4
  require 'pdc/version'
@@ -7,6 +7,7 @@ module PDC
7
7
  include PDC::Resource::Attributes
8
8
  include PDC::Resource::Scopes
9
9
  include PDC::Resource::RestApi
10
+ include PDC::Resource::Associations
10
11
 
11
12
  scope :page, ->(value) { where(page: value) }
12
13
  scope :page_size, ->(value) { where(page_size: value) }
@@ -1,7 +1,6 @@
1
1
  require 'faraday-http-cache'
2
2
  require 'pdc/http/request/token_fetcher'
3
3
 
4
- # rubocop:disable ModuleLength
5
4
  module PDC
6
5
  # This class is the main access point for all PDC::Resource instances.
7
6
  #
@@ -23,17 +22,13 @@ module PDC
23
22
  Config = Struct.new(
24
23
  :site,
25
24
  :api_root,
26
-
27
25
  :ssl_verify_mode,
28
-
29
26
  :requires_token,
30
27
  :token_obtain_path,
31
28
  :token,
32
-
33
29
  :log_level,
34
30
  :enable_logging,
35
31
  :logger,
36
-
37
32
  :cache_store,
38
33
  :disable_caching
39
34
  ) do
@@ -76,7 +71,6 @@ module PDC
76
71
  def config=(new_config)
77
72
  @config = new_config
78
73
  apply_config
79
- @config
80
74
  end
81
75
 
82
76
  def token_url
@@ -113,7 +107,6 @@ module PDC
113
107
  end
114
108
 
115
109
  # resets and returns the +Faraday+ +connection+ object
116
- # rubocop:disable AbcSize
117
110
  def reset_base_connection
118
111
  faraday_config = {
119
112
  url: api_url,
@@ -4,7 +4,7 @@ require 'json'
4
4
  module PDC::Request
5
5
  module TokenFetcher
6
6
  module Configuration
7
- VALID_KEYS = [:ssl_verify_mode, :url].freeze
7
+ VALID_KEYS = %i[ssl_verify_mode url].freeze
8
8
 
9
9
  attr_accessor(*VALID_KEYS)
10
10
 
@@ -13,10 +13,8 @@ module PDC::Response
13
13
 
14
14
  metadata[PDC::Resource::PAGINATION] = {
15
15
  resource_count: metadata.delete(:count),
16
-
17
16
  # TODO: decide if this is okay to discard the
18
17
  # schema://host:port/ of the next and previous
19
-
20
18
  next_page: request_uri(metadata.delete(:next)),
21
19
  previous_page: request_uri(metadata.delete(:previous))
22
20
  }
@@ -10,3 +10,4 @@ require 'pdc/resource/scope_registry'
10
10
  require 'pdc/resource/relation'
11
11
  require 'pdc/resource/rest_api'
12
12
  require 'pdc/resource/wip'
13
+ require 'pdc/resource/associations'
@@ -0,0 +1,39 @@
1
+ require 'pdc/resource/associations/has_many'
2
+ require 'pdc/resource/associations/association'
3
+ require 'pdc/resource/associations/builder'
4
+
5
+ module PDC::Resource
6
+ module Associations
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ class_attribute :associations
11
+ self.associations = {}.freeze
12
+ end
13
+
14
+ module ClassMethods
15
+ def has_many(name, options = {})
16
+ create_association(name, HasMany, options)
17
+
18
+ define_method "#{name.to_s.singularize}_ids=" do |ids|
19
+ attributes[name] = []
20
+ ids.reject(&:blank?).each { |id| association(name).build(id: id) }
21
+ end
22
+
23
+ define_method "#{name.to_s.singularize}_ids" do
24
+ association(name).map(&:id)
25
+ end
26
+ end
27
+
28
+ def reflect_on_association(name)
29
+ associations[name] || associations[name.to_s.pluralize.to_sym]
30
+ end
31
+
32
+ private
33
+
34
+ def create_association(name, type, options)
35
+ self.associations = associations.merge(name => Builder.new(self, name, type, options))
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require 'pdc/resource/relation'
2
+
3
+ module PDC::Resource
4
+ module Associations
5
+ class Association < Relation
6
+ attr_reader :parent, :name
7
+
8
+ def initialize(klass, parent, name, options = {})
9
+ super(klass, options)
10
+ @parent = parent
11
+ @name = name
12
+ end
13
+
14
+ private
15
+
16
+ def foreign_key
17
+ (@options[:foreign_key] || "#{parent.class.model_name.element}_id").to_sym
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,46 @@
1
+ require 'active_support/dependencies'
2
+
3
+ module PDC::Resource
4
+ module Associations
5
+ class Builder
6
+ def initialize(parent_class, name, type, options = {})
7
+ @parent_class = parent_class
8
+ @name = name
9
+ @type = type
10
+ @options = options
11
+ end
12
+
13
+ def build(parent)
14
+ @type.new(klass, parent, @name, @options)
15
+ end
16
+
17
+ def klass
18
+ @klass ||= custom_class || compute_class(@name)
19
+ end
20
+
21
+ private
22
+
23
+ def custom_class
24
+ @options[:class_name].constantize if @options[:class_name]
25
+ end
26
+
27
+ # Compute class if no custom class name provided.
28
+ # Referencing the codes from rails in following link:
29
+ # https://github.com/rails/rails/blob/70ac072976c8cc6f013f0df3777e54ccae3f4f8c/activerecord/lib/active_record/inheritance.rb#L132-L150
30
+ def compute_class(type_name)
31
+ parent_name = @parent_class.to_s
32
+ type_name = type_name.to_s.classify
33
+
34
+ candidates = []
35
+ parent_name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
36
+ candidates << type_name
37
+
38
+ candidates.each do |candidate|
39
+ constant = ActiveSupport::Dependencies.safe_constantize(candidate)
40
+ return constant if candidate == constant.to_s
41
+ end
42
+ raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)
43
+ end
44
+ end
45
+ end
46
+ end