diff --git a/Gemfile b/Gemfile index c7373a0..6446707 100644 --- a/Gemfile +++ b/Gemfile @@ -20,9 +20,9 @@ end group :development do # code style gem "pronto", "0.11.0", require: false - gem "pronto-rubocop", "0.11.1", require: false - gem "rubocop", "1.23.0", require: false - gem "rubocop-rails", "2.12.4", require: false + gem "pronto-rubocop", "0.11.2", require: false + gem "rubocop", "1.31.2", require: false + gem "rubocop-rails", "2.15.2", require: false gem "rubocop-rake", "0.6.0", require: false # debugging diff --git a/Gemfile.lock b/Gemfile.lock index 2458e8d..2671158 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -63,15 +63,16 @@ GEM fuubar (2.5.1) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) - gitlab (4.17.0) - httparty (~> 0.18) - terminal-table (~> 1.5, >= 1.5.1) + gitlab (4.19.0) + httparty (~> 0.20) + terminal-table (>= 1.5.1) hashdiff (1.0.1) httparty (0.20.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) i18n (1.12.0) concurrent-ruby (~> 1.0) + json (2.6.2) json-schema (2.8.1) addressable (>= 2.4) json-schema-rspec (0.0.4) @@ -88,7 +89,7 @@ GEM method_source (1.0.0) mime-types (3.4.1) mime-types-data (~> 3.2015) - mime-types-data (3.2021.1115) + mime-types-data (3.2022.0105) mini_portile2 (2.8.0) minitest (5.16.2) multi_xml (0.6.0) @@ -100,8 +101,8 @@ GEM octokit (4.25.1) faraday (>= 1, < 3) sawyer (~> 0.9) - parallel (1.21.0) - parser (3.0.3.0) + parallel (1.22.1) + parser (3.1.2.0) ast (~> 2.4.1) pronto (0.11.0) gitlab (~> 4.4, >= 4.4.0) @@ -111,7 +112,7 @@ GEM rexml (~> 3.2) rugged (>= 0.23.0, < 1.1.0) thor (>= 0.20.3, < 2.0) - pronto-rubocop (0.11.1) + pronto-rubocop (0.11.2) pronto (~> 0.11.0) rubocop (>= 0.63.1, < 2.0) pry (0.14.1) @@ -137,12 +138,12 @@ GEM rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) - rainbow (3.0.0) + rainbow (3.1.1) rake (13.0.6) rb-fsevent (0.11.0) rb-inotify (0.10.1) ffi (~> 1.0) - regexp_parser (2.1.1) + regexp_parser (2.5.0) rexml (3.2.5) rspec (3.10.0) rspec-core (~> 3.10.0) @@ -168,18 +169,19 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.10.3) - rubocop (1.23.0) + rubocop (1.31.2) + json (~> 2.3) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.12.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.18.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.13.0) - parser (>= 3.0.1.1) - rubocop-rails (2.12.4) + rubocop-ast (1.19.1) + parser (>= 3.1.1.0) + rubocop-rails (2.15.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.7.0, < 2.0) @@ -200,13 +202,14 @@ GEM simplecov (>= 0.4.1) simplecov_json_formatter (0.1.3) systemu (2.6.5) - terminal-table (1.6.0) + terminal-table (3.0.2) + unicode-display_width (>= 1.1.1, < 3) thor (1.2.1) typhoeus (1.4.0) ethon (>= 0.9.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - unicode-display_width (2.1.0) + unicode-display_width (2.2.0) uuid (2.3.9) macaddr (~> 1.0) valid (1.2.0) @@ -230,7 +233,7 @@ DEPENDENCIES listen nyan-cat-formatter pronto (= 0.11.0) - pronto-rubocop (= 0.11.1) + pronto-rubocop (= 0.11.2) pry pry-byebug rake @@ -238,8 +241,8 @@ DEPENDENCIES rspec-collection_matchers (~> 1.2.0) rspec-json_expectations (~> 2.1) rspec-rails (~> 5.0.1) - rubocop (= 1.23.0) - rubocop-rails (= 2.12.4) + rubocop (= 1.31.2) + rubocop-rails (= 2.15.2) rubocop-rake (= 0.6.0) simplecov (= 0.21.2) simplecov-rcov (= 0.2.3) diff --git a/diaspora_federation-json_schema.gemspec b/diaspora_federation-json_schema.gemspec index 0bbf5c6..35f109b 100644 --- a/diaspora_federation-json_schema.gemspec +++ b/diaspora_federation-json_schema.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.email = ["benjamin@coding4.coffee", "senya@riseup.net"] s.homepage = "https://github.com/diaspora/diaspora_federation" s.summary = "diaspora* federation json schemas" - s.description = "This gem provides JSON schemas (currently one schema) for "\ + s.description = "This gem provides JSON schemas (currently one schema) for " \ "validating JSON serialized federation objects." s.license = "AGPL-3.0" s.metadata = { diff --git a/diaspora_federation-test.gemspec b/diaspora_federation-test.gemspec index b64cb19..24a949d 100644 --- a/diaspora_federation-test.gemspec +++ b/diaspora_federation-test.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.email = ["benjamin@coding4.coffee"] s.homepage = "https://github.com/diaspora/diaspora_federation" s.summary = "diaspora* federation test utils" - s.description = "This gem provides some supplimentary code (factory definitions), that"\ + s.description = "This gem provides some supplimentary code (factory definitions), that" \ "helps to build tests for users of the diaspora_federation gem." s.license = "AGPL-3.0" s.metadata = { diff --git a/lib/diaspora_federation/discovery/discovery.rb b/lib/diaspora_federation/discovery/discovery.rb index 3646ced..42de88a 100644 --- a/lib/diaspora_federation/discovery/discovery.rb +++ b/lib/diaspora_federation/discovery/discovery.rb @@ -38,8 +38,8 @@ module DiasporaFederation # Validates if the diaspora* ID matches the diaspora* ID in the webfinger response return if diaspora_id == clean_diaspora_id(webfinger.acct_uri) - raise DiscoveryError, "diaspora* ID does not match: Wanted #{diaspora_id} but got" \ - " #{clean_diaspora_id(webfinger.acct_uri)}" + raise DiscoveryError, "diaspora* ID does not match: Wanted #{diaspora_id} but got " \ + "#{clean_diaspora_id(webfinger.acct_uri)}" end def clean_diaspora_id(diaspora_id) diff --git a/lib/diaspora_federation/discovery/xrd_document.rb b/lib/diaspora_federation/discovery/xrd_document.rb index 576bfff..bea6fae 100644 --- a/lib/diaspora_federation/discovery/xrd_document.rb +++ b/lib/diaspora_federation/discovery/xrd_document.rb @@ -136,10 +136,7 @@ module DiasporaFederation private - # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor Style/AccessorGrouping - attr_reader :expires - attr_reader :subject - # rubocop:enable Layout/EmptyLinesAroundAttributeAccessor Style/AccessorGrouping + attr_reader :expires, :subject NS = {xrd: XMLNS}.freeze diff --git a/lib/diaspora_federation/entities/relayable.rb b/lib/diaspora_federation/entities/relayable.rb index 58a954f..86de19b 100644 --- a/lib/diaspora_federation/entities/relayable.rb +++ b/lib/diaspora_federation/entities/relayable.rb @@ -131,7 +131,7 @@ module DiasporaFederation data = super order = signature_order order += %i[author_signature] unless author == parent.root.author - order.map {|element| [element, data[element].to_s] }.to_h + order.to_h {|element| [element, data[element].to_s] } end def signature_order=(order) diff --git a/lib/diaspora_federation/entity.rb b/lib/diaspora_federation/entity.rb index 65a7b21..e67adf5 100644 --- a/lib/diaspora_federation/entity.rb +++ b/lib/diaspora_federation/entity.rb @@ -77,7 +77,7 @@ module DiasporaFederation # Nested entities are also converted to a Hash. # @return [Hash] entity data (mostly equal to the hash used for initialization). def to_h - enriched_properties.map {|key, value| + enriched_properties.to_h {|key, value| type = self.class.class_props[key] if type.instance_of?(Symbol) || value.nil? @@ -87,7 +87,7 @@ module DiasporaFederation elsif type.instance_of?(Array) [key, value.map(&:to_h)] end - }.to_h + } end # Returns the XML representation for this entity constructed out of @@ -273,7 +273,7 @@ module DiasporaFederation end def normalized_properties - properties.map {|name, value| [name, normalize_property(name, value)] }.to_h + properties.to_h {|name, value| [name, normalize_property(name, value)] } end def normalize_property(name, value) diff --git a/lib/diaspora_federation/federation/sender.rb b/lib/diaspora_federation/federation/sender.rb index 37f7a72..0781235 100644 --- a/lib/diaspora_federation/federation/sender.rb +++ b/lib/diaspora_federation/federation/sender.rb @@ -26,7 +26,7 @@ module DiasporaFederation def self.private(sender_id, obj_str, targets) hydra = HydraWrapper.new(sender_id, obj_str) targets.each {|url, json| hydra.insert_enc_magic_env_request(url, json) } - hydra.send.map {|url| [url, targets[url]] }.to_h + hydra.send.to_h {|url| [url, targets[url]] } end end end diff --git a/lib/diaspora_federation/parsers/json_parser.rb b/lib/diaspora_federation/parsers/json_parser.rb index b91dad7..5655f81 100644 --- a/lib/diaspora_federation/parsers/json_parser.rb +++ b/lib/diaspora_federation/parsers/json_parser.rb @@ -17,7 +17,7 @@ module DiasporaFederation private def parse_entity_data(entity_data) - hash = entity_data.map {|key, value| + hash = entity_data.to_h {|key, value| property = entity_type.class_props.keys.find {|name| name.to_s == key } if property type = entity_type.class_props[property] @@ -25,7 +25,7 @@ module DiasporaFederation else [key, value] end - }.to_h + } [hash] end @@ -49,9 +49,7 @@ module DiasporaFederation end def from_json_sanity_validation(json_hash) - missing = %w[entity_type entity_data].map {|prop| - prop if json_hash[prop].nil? - }.compact.join(", ") + missing = %w[entity_type entity_data].select {|prop| json_hash[prop].nil? }.join(", ") raise DeserializationError, "Required properties are missing in JSON object: #{missing}" unless missing.empty? assert_parsability_of(json_hash["entity_type"]) diff --git a/lib/diaspora_federation/parsers/xml_parser.rb b/lib/diaspora_federation/parsers/xml_parser.rb index d9f675d..83d46d6 100644 --- a/lib/diaspora_federation/parsers/xml_parser.rb +++ b/lib/diaspora_federation/parsers/xml_parser.rb @@ -14,7 +14,7 @@ module DiasporaFederation def parse(root_node) from_xml_sanity_validation(root_node) - hash = root_node.element_children.uniq(&:name).map {|child| + hash = root_node.element_children.uniq(&:name).to_h {|child| property, type = find_property_for(child.name) if property value = parse_element_from_node(child.name, type, root_node) @@ -22,7 +22,7 @@ module DiasporaFederation else [child.name, child.text] end - }.to_h + } [hash] end diff --git a/lib/diaspora_federation/properties_dsl.rb b/lib/diaspora_federation/properties_dsl.rb index 715573a..f93e52f 100644 --- a/lib/diaspora_federation/properties_dsl.rb +++ b/lib/diaspora_federation/properties_dsl.rb @@ -57,7 +57,7 @@ module DiasporaFederation # resolved on each call # @return [Hash] default values def default_values - optional_props.map {|name| [name, nil] }.to_h.merge(default_props).transform_values {|prop| + optional_props.to_h {|name| [name, nil] }.merge(default_props).transform_values {|prop| prop.respond_to?(:call) ? prop.call : prop } end @@ -65,7 +65,7 @@ module DiasporaFederation # @param [Hash] data entity data # @return [Hash] hash with resolved aliases def resolv_aliases(data) - data.map {|name, value| + data.to_h {|name, value| if class_prop_aliases.has_key? name prop_name = class_prop_aliases[name] raise InvalidData, "only use '#{name}' OR '#{prop_name}'" if data.has_key? prop_name @@ -74,7 +74,7 @@ module DiasporaFederation else [name, value] end - }.to_h + } end private diff --git a/spec/lib/diaspora_federation/entity_spec.rb b/spec/lib/diaspora_federation/entity_spec.rb index bc905e0..60b33b9 100644 --- a/spec/lib/diaspora_federation/entity_spec.rb +++ b/spec/lib/diaspora_federation/entity_spec.rb @@ -117,9 +117,9 @@ module DiasporaFederation it "returns a hash of the internal data" do entity = Entities::TestDefaultEntity.new(data) expect(entity.to_h).to eq( - data.map {|key, value| + data.to_h {|key, value| [key, entity.class.class_props[key] == :string ? value.to_s : value] - }.to_h + } ) end end diff --git a/spec/lib/diaspora_federation_spec.rb b/spec/lib/diaspora_federation_spec.rb index e95fe6e..3ff1f7f 100644 --- a/spec/lib/diaspora_federation_spec.rb +++ b/spec/lib/diaspora_federation_spec.rb @@ -43,7 +43,7 @@ module DiasporaFederation after do DiasporaFederation.certificate_authorities = @certificate_authorities - ::Rails.env = ENV["RAILS_ENV"] || "test" + ::Rails.env = ENV.fetch("RAILS_ENV", "test") end end