diff --git a/.rubocop.yml b/.rubocop.yml index 01f9380..125d500 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,17 @@ AllCops: DisplayCopNames: true + TargetRubyVersion: 2.4 + +## Metrics ##################################################################### + +Metrics/BlockLength: + Exclude: + - "Guardfile" + - "spec/**/*" + +Metrics/MethodLength: + CountComments: false + Max: 15 ## Styles ###################################################################### @@ -53,9 +65,3 @@ Style/EmptyCaseCondition: # end Style/TrivialAccessors: Enabled: false - -## Metrics ##################################################################### - -Metrics/MethodLength: - CountComments: false - Max: 15 diff --git a/.travis.yml b/.travis.yml index a6d8d16..d39bea2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,19 @@ env: - JRUBY_OPTS="$JRUBY_OPTS --debug" language: ruby rvm: - - 2.0.0 - 2.1 - 2.2 - 2.3.0 + - 2.3.1 + - 2.3.2 + - 2.3.3 - 2.4.0 + - ruby-head - jruby-9.1.6.0 + - jruby-head matrix: + allow_failures: + - rvm: ruby-head + - rvm: jruby-head fast_finish: true sudo: false diff --git a/Gemfile b/Gemfile index e9e2b0a..f7282a3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,23 +1,25 @@ +# frozen_string_literal: true + source "https://rubygems.org" gem "rake" group :development do - gem "pry" gem "guard" gem "guard-rspec", :require => false + gem "pry" end group :test do gem "coveralls" gem "rspec", "~> 3.1" + gem "rubocop", "= 0.47.0" gem "simplecov", ">= 0.9" - gem "rubocop", "= 0.40.0" end group :doc do - gem "yard" gem "redcarpet" + gem "yard" end # Specify your gem's dependencies in form_data.gemspec diff --git a/Guardfile b/Guardfile index 7d6acb4..60f47a2 100644 --- a/Guardfile +++ b/Guardfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + guard :rspec, :cmd => "bundle exec rspec" do require "guard/rspec/dsl" dsl = Guard::RSpec::Dsl.new(self) diff --git a/README.md b/README.md index ccbc2e7..411ea8a 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,6 @@ socket << form.to_s This library aims to support and is [tested against][ci] the following Ruby versions: -* Ruby 2.0.0 * Ruby 2.1.x * Ruby 2.2.x * Ruby 2.3.x diff --git a/Rakefile b/Rakefile index 158675f..028126f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,4 @@ -#!/usr/bin/env rake +# frozen_string_literal: true require "bundler/gem_tasks" diff --git a/appveyor.yml b/appveyor.yml index 900265c..7b50d35 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,5 @@ version: "#{build}" build: off -init: - - git config --global core.autocrlf true install: - set PATH=C:\Ruby23\bin;%PATH% - bundle install diff --git a/http-form_data.gemspec b/http-form_data.gemspec index bb24696..92e0d32 100644 --- a/http-form_data.gemspec +++ b/http-form_data.gemspec @@ -1,4 +1,5 @@ -# coding: utf-8 +# frozen_string_literal: true + lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "http/form_data/version" diff --git a/lib/http/form_data.rb b/lib/http/form_data.rb index 9179a30..73749af 100644 --- a/lib/http/form_data.rb +++ b/lib/http/form_data.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "http/form_data/file" require "http/form_data/multipart" require "http/form_data/urlencoded" @@ -26,7 +28,7 @@ module HTTP # socket << form.to_s module FormData # CRLF - CRLF = "\r\n".freeze + CRLF = "\r\n" # Generic FormData error. class Error < StandardError; end diff --git a/lib/http/form_data/file.rb b/lib/http/form_data/file.rb index 900eddc..adcf5de 100644 --- a/lib/http/form_data/file.rb +++ b/lib/http/form_data/file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module HTTP module FormData # Represents file form param. @@ -18,7 +20,7 @@ module FormData # FormData::File.new "/home/ixti/avatar.png" class File # Default MIME type - DEFAULT_MIME = "application/octet-stream".freeze + DEFAULT_MIME = "application/octet-stream" attr_reader :mime_type, :filename diff --git a/lib/http/form_data/multipart.rb b/lib/http/form_data/multipart.rb index 2c75dfb..efd850f 100644 --- a/lib/http/form_data/multipart.rb +++ b/lib/http/form_data/multipart.rb @@ -1,7 +1,7 @@ -# stdlib +# frozen_string_literal: true + require "securerandom" -# internal require "http/form_data/multipart/param" module HTTP @@ -11,7 +11,7 @@ class Multipart # @param [#to_h, Hash] data form data key-value Hash def initialize(data) @parts = Param.coerce FormData.ensure_hash data - @boundary = ("-" * 21) << SecureRandom.hex(21) + @boundary = (Array.new(21, "-") << SecureRandom.hex(21)).join("") @content_length = nil end diff --git a/lib/http/form_data/multipart/param.rb b/lib/http/form_data/multipart/param.rb index a8617de..32b9c90 100644 --- a/lib/http/form_data/multipart/param.rb +++ b/lib/http/form_data/multipart/param.rb @@ -1,21 +1,23 @@ +# frozen_string_literal: true + module HTTP module FormData class Multipart # Utility class to represent multi-part chunks class Param + CONTENT_DISPOSITION = "" + # @param [#to_s] name # @param [FormData::File, #to_s] value def initialize(name, value) - @name = name.to_s - @value = value - + @name = name.to_s + @value = value @header = "Content-Disposition: form-data; name=#{@name.inspect}" return unless file? - @header << "; filename=#{value.filename.inspect}" - @header << CRLF - @header << "Content-Type: #{value.mime_type}" + @header = "#{@header}; filename=#{value.filename.inspect}#{CRLF}" \ + "Content-Type: #{value.mime_type}" end # Returns body part with headers and data. diff --git a/lib/http/form_data/urlencoded.rb b/lib/http/form_data/urlencoded.rb index 16ba9cc..6e09dc9 100644 --- a/lib/http/form_data/urlencoded.rb +++ b/lib/http/form_data/urlencoded.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "uri" module HTTP diff --git a/lib/http/form_data/version.rb b/lib/http/form_data/version.rb index b2bf8cc..82a2ad4 100644 --- a/lib/http/form_data/version.rb +++ b/lib/http/form_data/version.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module HTTP module FormData # Gem version. - VERSION = "1.0.1".freeze + VERSION = "1.0.1" end end diff --git a/spec/lib/http/form_data/file_spec.rb b/spec/lib/http/form_data/file_spec.rb index 8dd5cee..e7564b9 100644 --- a/spec/lib/http/form_data/file_spec.rb +++ b/spec/lib/http/form_data/file_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # coding: utf-8 RSpec.describe HTTP::FormData::File do diff --git a/spec/lib/http/form_data/multipart_spec.rb b/spec/lib/http/form_data/multipart_spec.rb index de7176a..8571fab 100644 --- a/spec/lib/http/form_data/multipart_spec.rb +++ b/spec/lib/http/form_data/multipart_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe HTTP::FormData::Multipart do let(:file) { HTTP::FormData::File.new fixture "the-http-gem.info" } let(:params) { { :foo => :bar, :baz => file } } diff --git a/spec/lib/http/form_data/urlencoded_spec.rb b/spec/lib/http/form_data/urlencoded_spec.rb index 6628c93..3279ab0 100644 --- a/spec/lib/http/form_data/urlencoded_spec.rb +++ b/spec/lib/http/form_data/urlencoded_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # coding: utf-8 RSpec.describe HTTP::FormData::Urlencoded do diff --git a/spec/lib/http/form_data_spec.rb b/spec/lib/http/form_data_spec.rb index 980790f..9798ab8 100644 --- a/spec/lib/http/form_data_spec.rb +++ b/spec/lib/http/form_data_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe HTTP::FormData do describe ".create" do subject { HTTP::FormData.create params } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f24ed16..76f5f92 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# frozen_string_literal: true require "simplecov" require "coveralls" diff --git a/spec/support/fixtures_helper.rb b/spec/support/fixtures_helper.rb index 0dd3498..a3ef8ba 100644 --- a/spec/support/fixtures_helper.rb +++ b/spec/support/fixtures_helper.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# frozen_string_literal: true require "pathname"