Skip to content

Commit

Permalink
safe autocorect rubocop erros
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkit110 committed Aug 30, 2024
1 parent 8e7d55f commit aba071a
Show file tree
Hide file tree
Showing 54 changed files with 374 additions and 373 deletions.
19 changes: 9 additions & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require: rubocop-rails

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/HashSyntax:
EnforcedStyle: hash_rockets

Style/Documentation:
Enabled: false
inherit_gem:
rubocop-github:
- config/default.yml # generic Ruby rules and cops
- config/rails.yml # Rails-specific rules and cops

AllCops:
NewCops: enable
Exclude:
- "test/dummy/db/schema.rb"
- "bin/*"
- "test/dummy/db/migrate/*_engine.rb"
- vendor/bundle/**/*
17 changes: 17 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@ source "https://rubygems.org"
gemspec

gem "debug"

group :development do
gem "rubocop-github", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
gem "ruby-lsp", require: false

gem "delayed_job_active_record", "~> 4.0"
gem "mini_magick", "~> 5.0.1"
gem "minitest-reporters", "~> 1.0"
gem "mocha", "~> 2.0"
gem "pry", "~> 0.10"
gem "simplecov", "~> 0.8"
gem "spawnling", "~> 2.1"
gem "sqlite3", "~> 2.0"
gem "zencoder", "~> 2.5"
end
31 changes: 14 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
begin
require 'bundler/setup'
require "bundler/setup"
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
end

require 'rdoc/task'
require "rdoc/task"

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Fogged'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.md')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_dir = "rdoc"
rdoc.title = "Fogged"
rdoc.options << "--line-numbers"
rdoc.rdoc_files.include("README.md")
rdoc.rdoc_files.include("lib/**/*.rb")
end

APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'


APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
load "rails/tasks/engine.rake"

Bundler::GemHelper.install_tasks

require 'rake/testtask'
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.libs << "lib"
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end


task default: :test
50 changes: 25 additions & 25 deletions app/controllers/fogged/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
# }
module Fogged
class ResourcesController < Fogged.parent_controller.constantize
before_action :select_resourceables, :only => :index
before_action :select_resource, :only => %i[confirm destroy show update]
skip_before_action :verify_authenticity_token, :only => :zencoder_notification
before_action :select_resourceables, only: :index
before_action :select_resource, only: %i[confirm destroy show update]
skip_before_action :verify_authenticity_token, only: :zencoder_notification

# List all resources. Parameter type is mandatory. It indicates in which
# "context" you want all resources. You can refine the search, using
Expand All @@ -89,10 +89,10 @@ def index
resourceable.resources.search(params)
end

render :json => paginate(resources.flatten.uniq),
:adapter => :json,
:meta => @meta,
:each_serializer => ResourceSerializer
render json: paginate(resources.flatten.uniq),
adapter: :json,
meta: @meta,
each_serializer: ResourceSerializer
end

# Get the resource.
Expand All @@ -107,9 +107,9 @@ def index
# Raises 404 if the Resource is not found
# Raises 500 if an error occurs
def show
render :json => @resource,
:adapter => :json,
:serializer => ResourceSerializer
render json: @resource,
adapter: :json,
serializer: ResourceSerializer
end

# Create a new resource. You must provide a filename (example: foo.png)
Expand Down Expand Up @@ -137,12 +137,12 @@ def create
resource_attributes = resource_params.except(:filename)
resource_attributes[:extension] = extension(resource_params.require(:filename))

resource = Resource.create!(resource_attributes.merge(:uploading => true))
resource = Resource.create!(resource_attributes.merge(uploading: true))

render :json => resource,
:adapter => :json,
:serializer => ResourceSerializer,
:include_upload_url => true
render json: resource,
adapter: :json,
serializer: ResourceSerializer,
include_upload_url: true
end

# Update a Resource. You can update the name of a Resource or its context
Expand Down Expand Up @@ -183,7 +183,7 @@ def update
# Raises 500 if a server errors occurs
def confirm
@resource.process!
@resource.update!(:uploading => false)
@resource.update!(uploading: false)
show
end

Expand All @@ -204,15 +204,15 @@ def destroy
end

def zencoder_notification
if (resource = Resource.find_by(:encoding_job_id => job_params[:id])) &&
if (resource = Resource.find_by(encoding_job_id: job_params[:id])) &&
(file = params[:outputs].try(:first)) &&
job_params[:state] == "finished"

resource.update!(
:encoding_progress => 100,
:width => file[:width],
:height => file[:height],
:duration => file[:duration_in_ms].to_f / 1000.0
encoding_progress: 100,
width: file[:width],
height: file[:height],
duration: file[:duration_in_ms].to_f / 1000.0
)
end

Expand All @@ -225,7 +225,7 @@ def select_resourceables
ids = params[:type_id] || params[:type_ids]
ids = [ids] unless ids.respond_to?(:to_ary)
@resourceables = resourceable_clazz.all
@resourceables = resourceable_clazz.where(:id => ids) if ids.try(:any?)
@resourceables = resourceable_clazz.where(id: ids) if ids.try(:any?)
end

def resourceable_clazz
Expand Down Expand Up @@ -259,9 +259,9 @@ def paginate(result)
offset = (page - 1) * count
total = result.size
@meta = {
:pagination => {
:total => total,
:remaining => [total - offset - count, 0].max
pagination: {
total:,
remaining: [total - offset - count, 0].max
}
}

Expand Down
12 changes: 6 additions & 6 deletions app/jobs/fogged/resources/awsthumbnailjob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def perform(resource)

step = 100 / Fogged.thumbnail_sizes.size
Fogged.thumbnail_sizes.each_with_index do |size, index|
Tempfile.open(source_from(resource.url), :binmode => true, :encoding => "ascii-8bit") do |source|
Tempfile.open(source_from(resource.url), binmode: true, encoding: "ascii-8bit") do |source|
Tempfile.open(["thumbnail", ".png"]) do |t|
source.write(URI.parse(resource.url).read)
source.flush
Expand All @@ -18,17 +18,17 @@ def perform(resource)
end

Fogged.resources.files.create(
:key => resource.send(:fogged_name_for, :thumbnails, index),
:body => File.read(t.path),
:public => true,
:content_type => Mime[:png].to_s
key: resource.send(:fogged_name_for, :thumbnails, index),
body: File.read(t.path),
public: true,
content_type: Mime[:png].to_s
)
end
end

resource.increment!(:encoding_progress, step)
end
resource.update!(:encoding_progress => 100)
resource.update!(encoding_progress: 100)
end

private
Expand Down
35 changes: 20 additions & 15 deletions app/models/fogged/resource.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Fogged
class Resource < ActiveRecord::Base
validates :extension, :content_type, :name, :presence => true
validates :extension, :content_type, :name, presence: true

before_save :ensure_token
after_destroy :destroy_fogged_file
Expand All @@ -11,7 +11,7 @@ def self.search(params)
if params[:query]
results = results.where(
"#{table_name}.name LIKE :query",
:query => "%#{params[:query].to_s.downcase}%"
query: "%#{params[:query].to_s.downcase}%"
)
end

Expand All @@ -34,28 +34,30 @@ def url

def h264_url
return unless video? && Fogged.zencoder_enabled

url.gsub(fogged_name, fogged_name_for(:h264))
end

def mpeg_url
return unless video? && Fogged.zencoder_enabled

url.gsub(fogged_name, fogged_name_for(:mpeg))
end

def webm_url
return unless video? && Fogged.zencoder_enabled

url.gsub(fogged_name, fogged_name_for(:webm))
end

def thumbnail_urls
return unless Fogged.active_job_enabled

case
when video? && Fogged.zencoder_enabled
if video? && Fogged.zencoder_enabled
5.times.map do |n|
url.gsub(fogged_name, fogged_name_for(:thumbnails, n))
end
when image? && Fogged.minimagick_enabled
elsif image? && Fogged.minimagick_enabled
Fogged.thumbnail_sizes.size.times.map do |n|
url.gsub(fogged_name, fogged_name_for(:thumbnails, n))
end
Expand All @@ -75,6 +77,7 @@ def encoding?
(video? || (image? && Fogged.active_job_enabled))
return
end

encoding_progress < 100
end

Expand All @@ -97,9 +100,9 @@ def fogged_file

def create_fogged_file(files)
files.create(
:key => fogged_name,
:body => "",
:content_type => content_type
key: fogged_name,
body: "",
content_type:
).tap do |file|
file.public = "public_read"
file.save
Expand All @@ -109,15 +112,17 @@ def create_fogged_file(files)
def find_size!
if Fogged.test_enabled
return update!(
:width => 800,
:height => 600
width: 800,
height: 600
)
end
size = FastImage.size(url)
return if size.blank?

update!(
:width => size.first,
:height => size.second
) unless size.blank?
width: size.first,
height: size.second
)
end

def encode!(inline = false)
Expand All @@ -133,7 +138,7 @@ def ensure_token
def generate_token
loop do
a_token = SecureRandom.hex(16)
break a_token unless Resource.find_by(:token => a_token)
break a_token unless Resource.find_by(token: a_token)
end
end

Expand All @@ -154,7 +159,7 @@ def fogged_name_for(type, number = 0)
when :thumbnails
"#{token}-thumbnail-#{number}.png"
else
fail(ArgumentError, "Can't get fogged name of #{type}")
raise(ArgumentError, "Can't get fogged name of #{type}")
end
end

Expand Down
Loading

0 comments on commit aba071a

Please sign in to comment.