diff --git a/app/models/auth_provider.rb b/app/models/auth_provider.rb index e54b0766a..25df71439 100644 --- a/app/models/auth_provider.rb +++ b/app/models/auth_provider.rb @@ -1,5 +1,6 @@ -class AuthProvider < ActiveRecord::Base +# frozen_string_literal: true +class AuthProvider < ActiveRecord::Base # this is a simple stub used for database creation & configuration class SimpleAuthProvider < Object def providable_type diff --git a/app/validators/file_mime_type_validator.rb b/app/validators/file_mime_type_validator.rb index 43c384521..7e25e2562 100644 --- a/app/validators/file_mime_type_validator.rb +++ b/app/validators/file_mime_type_validator.rb @@ -1,11 +1,12 @@ +# frozen_string_literal: true + # Based on: https://gist.github.com/1298417 - class FileMimeTypeValidator < ActiveModel::EachValidator - MESSAGES = { :content_type => :wrong_content_type }.freeze - CHECKS = [ :content_type ].freeze + MESSAGES = { content_type: :wrong_content_type }.freeze + CHECKS = [:content_type].freeze - DEFAULT_TOKENIZER = lambda { |value| value.split(//) } - RESERVED_OPTIONS = [:content_type, :tokenizer] + DEFAULT_TOKENIZER = ->(value) { value.split(//) } + RESERVED_OPTIONS = %i[content_type tokenizer].freeze def initialize(options) super @@ -14,33 +15,29 @@ class FileMimeTypeValidator < ActiveModel::EachValidator def check_validity! keys = CHECKS & options.keys - - if keys.empty? - raise ArgumentError, 'Patterns unspecified. Specify the :content_type option.' - end + raise ArgumentError, 'Patterns unspecified. Specify the :content_type option.' if keys.empty? keys.each do |key| value = options[key] + raise ArgumentError, ":#{key} must be a String or a Regexp or an Array" unless valid_content_type_option?(value) - unless valid_content_type_option?(value) - raise ArgumentError, ":#{key} must be a String or a Regexp or an Array" - end + next unless key.is_a?(Array) && key == :content_type - if key.is_a?(Array) && key == :content_type - options[key].each do |val| - raise ArgumentError, "#{val} must be a String or a Regexp" unless val.is_a?(String) || val.is_a?(Regexp) - end + options[key].each do |val| + raise ArgumentError, "#{val} must be a String or a Regexp" unless val.is_a?(String) || val.is_a?(Regexp) end end end def validate_each(record, attribute, value) - raise(ArgumentError, 'A CarrierWave::Uploader::Base object was expected') unless value.kind_of? CarrierWave::Uploader::Base - value = (options[:tokenizer] || DEFAULT_TOKENIZER).call(value) if value.kind_of?(String) - return if value.length == 0 + raise(ArgumentError, 'A CarrierWave::Uploader::Base object was expected') unless value.is_a? CarrierWave::Uploader::Base + + value = (options[:tokenizer] || DEFAULT_TOKENIZER).call(value) if value.is_a?(String) + return if value.length.zero? CHECKS.each do |key| next unless check_value = options[key] + do_validation(value, check_value, key, record, attribute) if key == :content_type end end @@ -57,16 +54,17 @@ class FileMimeTypeValidator < ActiveModel::EachValidator private def valid_content_type_option?(content_type) - return true if %w{Array String Regexp}.include?(content_type.class.to_s) + return true if %w[Array String Regexp].include?(content_type.class.to_s) + false end def do_validation(value, pattern, key, record, attribute) if pattern.is_a?(String) || pattern.is_a?(Regexp) - return if value.file.content_type.send((pattern.is_a?(String) ? '==' : '=~' ), pattern) + return if value.file.content_type.send((pattern.is_a?(String) ? '==' : '=~'), pattern) else valid_list = pattern.map do |p| - value.file.content_type.send((p.is_a?(String) ? '==' : '=~' ), p) + value.file.content_type.send((p.is_a?(String) ? '==' : '=~'), p) end return if valid_list.include?(true) end @@ -78,4 +76,4 @@ class FileMimeTypeValidator < ActiveModel::EachValidator record.errors.add(attribute, MESSAGES[key], errors_options) end -end \ No newline at end of file +end diff --git a/app/views/api/invoices/list.json.jbuilder b/app/views/api/invoices/list.json.jbuilder index 76e11a5b1..97336dab1 100644 --- a/app/views/api/invoices/list.json.jbuilder +++ b/app/views/api/invoices/list.json.jbuilder @@ -6,7 +6,7 @@ json.array!(@invoices) do |invoice| json.maxInvoices max_invoices json.extract! invoice, :id, :created_at, :reference, :invoiced_type, :avoir_date json.user_id invoice.invoicing_profile.user_id - json.total (invoice.total / 100.00) + json.total invoice.total / 100.00 json.url invoice_url(invoice, format: :json) json.name invoice.invoicing_profile.full_name json.has_avoir invoice.refunded?