Skip to content

Commit

Permalink
Add RuboCop
Browse files Browse the repository at this point in the history
  • Loading branch information
blocknotes committed Apr 7, 2021
1 parent 0d8e335 commit 12cbce0
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 11 deletions.
153 changes: 153 additions & 0 deletions .rubocop-https---relaxed-ruby-style-rubocop-yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Relaxed.Ruby.Style
## Version 2.5

Style/Alias:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylealias

Style/AsciiComments:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleasciicomments

Style/BeginBlock:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylebeginblock

Style/BlockDelimiters:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters

Style/CommentAnnotation:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylecommentannotation

Style/Documentation:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styledocumentation

Layout/DotPosition:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#layoutdotposition

Style/DoubleNegation:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styledoublenegation

Style/EndBlock:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleendblock

Style/FormatString:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleformatstring

Style/IfUnlessModifier:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier

Style/Lambda:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylelambda

Style/ModuleFunction:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylemodulefunction

Style/MultilineBlockChain:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain

Style/NegatedIf:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylenegatedif

Style/NegatedWhile:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile

Style/NumericPredicate:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate

Style/ParallelAssignment:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleparallelassignment

Style/PercentLiteralDelimiters:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters

Style/PerlBackrefs:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs

Style/Semicolon:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesemicolon

Style/SignalException:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesignalexception

Style/SingleLineBlockParams:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams

Style/SingleLineMethods:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods

Layout/SpaceBeforeBlockBraces:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces

Layout/SpaceInsideParens:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens

Style/SpecialGlobalVars:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars

Style/StringLiterals:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylestringliterals

Style/TrailingCommaInArguments:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments

Style/TrailingCommaInArrayLiteral:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral

Style/TrailingCommaInHashLiteral:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral

Style/SymbolArray:
Enabled: false
StyleGuide: http://relaxed.ruby.style/#stylesymbolarray

Style/WhileUntilModifier:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier

Style/WordArray:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylewordarray

Lint/AmbiguousRegexpLiteral:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral

Lint/AssignmentInCondition:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition

Layout/LineLength:
Enabled: false

Metrics:
Enabled: false

27 changes: 27 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
inherit_from:
- https://relaxed.ruby.style/rubocop.yml

AllCops:
Exclude:
- bin/*
- spec/dummy/**/*
NewCops: enable

Gemspec/RequiredRubyVersion:
Enabled: false

Naming/FileName:
Enabled: false

Layout/LineLength:
Enabled: true
Max: 120

Style/HashEachMethods:
Enabled: true

Style/HashTransformKeys:
Enabled: true

Style/HashTransformValues:
Enabled: true
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

5 changes: 4 additions & 1 deletion activeadmin_jfu_upload.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
lib = File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'activeadmin/jfu_upload/version'

Expand All @@ -23,6 +25,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'puma', '~> 4.3'
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
spec.add_development_dependency 'rspec-rails', '~> 4.0'
spec.add_development_dependency 'rubocop', '~> 0.90'
spec.add_development_dependency 'sassc', '~> 2.4'
spec.add_development_dependency 'selenium-webdriver', '~> 3.142'
spec.add_development_dependency 'simplecov', '~> 0.19'
Expand Down
29 changes: 29 additions & 0 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'rubocop' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rubocop", "rubocop")
2 changes: 2 additions & 0 deletions lib/activeadmin/jfu_upload.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'activeadmin/jfu_upload/engine'
11 changes: 7 additions & 4 deletions lib/activeadmin/jfu_upload/engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_admin'

module ActiveAdmin
Expand All @@ -13,19 +15,20 @@ def upload_file( request, param, resource, field )
resource.update field => param
response = { result: 1, file_name: resource.try( field ).try( :url ) }
else
m = request.headers['CONTENT-RANGE'].match( /[^\s]+\s(\d+)-(\d+)\/(\d+)/ )
m = request.headers['CONTENT-RANGE'].match(%r{[^\s]+\s(\d+)-(\d+)/(\d+)})
if m
buffer = param.read
pos = m[1].to_i
if pos == 0
tempfile = Rails.root.join('tmp', "upload_#{Time.now.to_i}_#{resource.id}_#{field}")
field_data = { original_filename: param.original_filename, tempfile: tempfile }
# dir.mkdir unless File.exists?(dir)
# field_data = { original_filename: param.original_filename, tempfile: dir.join(param.tempfile).to_s } # alternative: "#{resource.class.to_s.tableize}_#{resource.id}_#{Time.now.to_i}"
resource.update_column field, YAML::dump( field_data )
# field_data = { original_filename: param.original_filename, tempfile: dir.join(param.tempfile).to_s }
# # alternative: "#{resource.class.to_s.tableize}_#{resource.id}_#{Time.now.to_i}"
resource.update_column field, YAML.dump(field_data)
mode = 'wb'
else
field_data = YAML::load resource.read_attribute(field)
field_data = YAML.load resource.read_attribute(field) # rubocop:disable Security/YAMLLoad
mode = 'ab'
end
File.open(field_data[:tempfile], mode) { |f| f.write(buffer) }
Expand Down
4 changes: 3 additions & 1 deletion lib/activeadmin/jfu_upload/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

module ActiveAdmin
module JfuUpload
VERSION = '0.2.0'.freeze
VERSION = '0.2.0'
end
end
2 changes: 2 additions & 0 deletions lib/activeadmin_jfu_upload.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'activeadmin/jfu_upload'

require 'formtastic/inputs/jfu_upload_input'
10 changes: 6 additions & 4 deletions lib/formtastic/inputs/jfu_upload_input.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Formtastic
module Inputs
class JfuUploadInput < Formtastic::Inputs::FileInput
Expand All @@ -8,10 +10,10 @@ def input_html_options
def to_html
input_wrapping do
label_html <<
template.content_tag( :div, { class: 'jfu_upload_wrapper' } ) do
builder.file_field( method, input_html_options ) <<
template.content_tag( :ul )
end
template.content_tag(:div, { class: 'jfu_upload_wrapper' }) do
builder.file_field(method, input_html_options) <<
template.content_tag(:ul)
end
end
end
end
Expand Down

0 comments on commit 12cbce0

Please sign in to comment.