Run rubocop on all files

This commit is contained in:
2023-06-08 21:57:54 +10:00
parent 6a2bc82e3b
commit 9d9d8ccf6d
65 changed files with 114 additions and 158 deletions

View File

@@ -9,25 +9,24 @@ namespace :blog do
Dotenv.load("/home/blog/current/.env.production")
end
task :load_from_letterboxd => ["blog:load_environment"] do
task load_from_letterboxd: ["blog:load_environment"] do
require "hanami/prepare"
require "scraperd"
client = Scraperd::Base.new
activities = client.fetch('dnitza')
activities = client.fetch("dnitza")
create_command = Admin::Container["commands.movies.create"]
activities.each do |activity|
title = CGI.unescapeHTML(activity.title)
create_command.({
title: title,
year: activity.year,
url: activity.film_link,
watched_at: activity.watched_at
})
create_command.call({
title: title,
year: activity.year,
url: activity.film_link,
watched_at: activity.watched_at
})
end
end
end
end

View File

@@ -10,10 +10,10 @@ require "dry/matcher/result_matcher"
module Adamantium
class Action < Hanami::Action
include Deps["logger",
"settings",
not_found_view: "views.not_found",
error_view: "views.error",
sentry: "sentry.client"]
"settings",
not_found_view: "views.not_found",
error_view: "views.error",
sentry: "sentry.client"]
include Dry::Matcher.for(:handle, with: Dry::Matcher::ResultMatcher)
include Dry::Monads[:result]

View File

@@ -4,7 +4,6 @@ module Adamantium
module Actions
module Trips
class Show < Adamantium::Action
include Deps["views.trips.show"]
def handle(req, res)

View File

@@ -5,9 +5,9 @@ module Adamantium
include Deps["geo.gpx_parser", "commands.workouts.create"]
def handle(req, res)
tempfile = Tempfile.new(%w/path .gpx/)
tempfile = Tempfile.new(%w[path .gpx])
if req.params.to_h.dig(:file, :tempfile) != nil
if !req.params.to_h.dig(:file, :tempfile).nil?
tempfile.write req.params[:file][:tempfile].read
else
tempfile.write req.params[:file]
@@ -15,7 +15,6 @@ module Adamantium
tempfile.rewind
gpxfile = gpx_parser.call(path: tempfile.path)
if gpxfile.success?

View File

@@ -7,10 +7,10 @@ module Adamantium
def call(auto_tag_id: nil)
auto_taggings = if auto_tag_id
auto_tagging_repo.find(auto_tag_id)
else
auto_tagging_repo.all
end
auto_tagging_repo.find(auto_tag_id)
else
auto_tagging_repo.all
end
auto_taggings.each do |auto_tagging|
posts = auto_tagging.title_only? ?
@@ -19,7 +19,7 @@ module Adamantium
posts.each do |post|
post_repo.auto_tag_post(post_id: post.id,
tag_id: auto_tagging.tag_id)
tag_id: auto_tagging.tag_id)
end
end

View File

@@ -1,4 +1,3 @@
require "securerandom"
require "dry/monads"
require "filemagic"

View File

@@ -6,7 +6,6 @@ module Adamantium
module Decorators
module Movies
class Decorator < SimpleDelegator
include Deps["clients.omdb"]
def poster

View File

@@ -30,4 +30,4 @@ module Adamantium
end
end
end
end
end

View File

@@ -48,13 +48,12 @@ module Adamantium
end
def auto_tag_post(post_id:, tag_id:)
return if posts
.post_tags
.where(
post_id: post_id,
tag_id: tag_id
).count > 0
.post_tags
.where(
post_id: post_id,
tag_id: tag_id
).count > 0
posts
.post_tags

View File

@@ -8,4 +8,4 @@ module Adamantium
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Adamantium
module Views
module Movies
class Index < View
include Deps["repos.movie_repo"]
expose :movies do

View File

@@ -4,14 +4,14 @@ require "connection_pool"
require "que"
require "hanami/boot"
uri = URI.parse(ENV['DATABASE_URL'])
uri = URI.parse(ENV["DATABASE_URL"])
Que.connection = ConnectionPool.new(size: 10) do
PG::Connection.open(
host: uri.host,
user: uri.user,
host: uri.host,
user: uri.user,
password: uri.password,
port: uri.port || 5432,
dbname: uri.path[1..-1]
port: uri.port || 5432,
dbname: uri.path[1..]
)
end
end

View File

@@ -52,8 +52,10 @@ module Adamantium
mastodon_token = settings.mastodon_token
file = Tempfile.new(SecureRandom.uuid)
# rubocop:disable Security/Open
file.write(URI.open(photo["value"]).read)
file.rewind
# rubocop:enable Security/Open
file_size = file.size.to_f / 2**20
formatted_file_size = "%.2f" % file_size

View File

@@ -12,4 +12,4 @@ module Adamantium
end
end
end
end
end

View File

@@ -18,4 +18,4 @@ module Adamantium
end
end
end
end
end

View File

@@ -3,7 +3,7 @@ module Adamantium
class BasicAuth < Rack::Auth::Basic
def call(env)
request = Rack::Request.new(env)
if request.path.match(/^\/admin*/)
if /^\/admin*/.match?(request.path)
# Execute basic authentication
super(env)
else

View File

@@ -2,12 +2,11 @@ module Admin
module Actions
module AutoTagging
class Create < Action
include Deps["commands.auto_tagging.create",
"views.auto_tagging.index",
"validation.contracts.auto_tagging_contract",
auto_tag: "commands.auto_tagging.tag",
new_view: "views.auto_tagging.new"]
"views.auto_tagging.index",
"validation.contracts.auto_tagging_contract",
auto_tag: "commands.auto_tagging.tag",
new_view: "views.auto_tagging.new"]
def handle(req, res)
title_contains = req.params[:title_contains]
@@ -16,16 +15,16 @@ module Admin
tag_now = req.params[:tag_now]
validation = auto_tagging_contract.call(title_contains: title_contains,
body_contains: body_contains,
tag_id: tag_id)
body_contains: body_contains,
tag_id: tag_id)
if validation.success?
result = create.(title_contains: title_contains,
body_contains: body_contains,
tag_id: tag_id)
result = create.call(title_contains: title_contains,
body_contains: body_contains,
tag_id: tag_id)
if result.success? && tag_now
auto_tag.(auto_tag_id: result.value!)
auto_tag.call(auto_tag_id: result.value!)
end
res.render index
@@ -36,4 +35,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module AutoTagging
class Delete < Action
include Deps["repos.auto_tagging_repo"]
def handle(req, res)
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module AutoTagging
class Index < Action
include Deps["views.auto_tagging.index"]
def handle(req, res)
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module AutoTagging
class New < Action
include Deps[new_view: "views.auto_tagging.new"]
def handle(req, res)
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Bookmarks
class Archive < Action
include Deps["repos.bookmark_repo"]
def handle(req, res)
@@ -13,4 +12,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,19 +2,18 @@ module Admin
module Actions
module Bookmarks
class Cache < Action
include Deps["commands.bookmarks.cache"]
def handle(req, res)
bookmark_id = req.params[:id]
if cache.(bookmark_id: bookmark_id).success?
res.body = "Success"
res.body = if cache.call(bookmark_id: bookmark_id).success?
"Success"
else
res.body = "Failed"
"Failed"
end
end
end
end
end
end
end

View File

@@ -4,7 +4,6 @@ module Admin
module Actions
module Bookmarks
class Clean < Action
def handle(req, res)
Que.connection = Adamantium::Container["persistence.db"]
@@ -19,4 +18,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Bookmarks
class Delete < Action
include Deps["repos.bookmark_repo", "repos.post_tag_repo"]
def handle(req, res)
@@ -14,4 +13,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Bookmarks
class Index < Action
include Deps["views.bookmarks.index"]
def handle(req, res)
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -1,12 +1,11 @@
module Admin
module Actions
class Index < Action
include Deps["views.index"]
def handle(req, res)
res.render index
end
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module MergeTags
class Index < Action
include Deps["views.merge_tags.index"]
def handle(req, res)
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,14 +2,13 @@ module Admin
module Actions
module MergeTags
class Merge < Action
include Deps["commands.merge_tags.merge"]
def handle(req, res)
target_id = req.params[:target_id]
source_id = req.params[:source_id]
result = merge.(target_id: target_id, source_id: source_id)
result = merge.call(target_id: target_id, source_id: source_id)
if result.success?
res.redirect_to "/admin/tags/merge"
@@ -21,4 +20,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module MergeTags
class New < Action
include Deps[new_view: "views.merge_tags.new"]
def handle(req, res)
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Photos
class Index < Action
include Deps["views.photos.index"]
def handle(req, res)
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Posts
class Archive < Action
include Deps["repos.post_repo"]
def handle(req, res)
@@ -13,4 +12,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Posts
class Delete < Action
include Deps["repos.post_repo", "repos.post_tag_repo"]
def handle(req, res)
@@ -14,4 +13,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Posts
class Index < Action
include Deps["views.posts.index"]
def handle(req, res)
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Posts
class Publish < Action
include Deps["repos.post_repo"]
def handle(req, res)
post_id = req.params[:id]
@@ -12,4 +11,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Tags
class Delete < Action
include Deps["repos.post_tag_repo", "repos.tag_repo"]
def handle(req, res)
@@ -14,4 +13,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Actions
module Tags
class Index < Action
include Deps["views.tags.index"]
def handle(req, res)
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -4,7 +4,6 @@ module Admin
module Actions
module Trips
class AddPost < Admin::Action
include Deps["commands.trips.add_post"]
def handle(req, res)

View File

@@ -4,7 +4,6 @@ module Admin
module Actions
module Trips
class Create < Admin::Action
include Deps["commands.trips.create"]
def handle(req, res)

View File

@@ -4,7 +4,6 @@ module Admin
module Actions
module Trips
class Show < Admin::Action
include Deps["views.trips.show"]
def handle(req, res)

View File

@@ -4,7 +4,6 @@ module Admin
module Actions
module Trips
class Update < Admin::Action
include Deps["commands.trips.update"]
def handle(req, res)

View File

@@ -9,8 +9,8 @@ module Admin
Failure() if !title_contains.empty? && !body_contains.empty?
result = auto_tagging_repo.create(title_contains: title_contains,
body_contains: body_contains,
tag_id: tag_id)
body_contains: body_contains,
tag_id: tag_id)
Success(result.id)
end

View File

@@ -7,10 +7,10 @@ module Admin
def call(auto_tag_id: nil)
auto_taggings = if auto_tag_id
auto_tagging_repo.find(auto_tag_id)
else
auto_tagging_repo.all
end
auto_tagging_repo.find(auto_tag_id)
else
auto_tagging_repo.all
end
auto_taggings.each do |auto_tagging|
posts = auto_tagging.title_only? ?
@@ -19,7 +19,7 @@ module Admin
posts.each do |post|
post_repo.tag_post(post_id: post.id,
tag_id: auto_tagging.tag_id)
tag_id: auto_tagging.tag_id)
end
end

View File

@@ -8,7 +8,7 @@ module Admin
include Dry::Monads[:result]
include Deps["repos.bookmark_repo"]
def call(bookmark_id: )
def call(bookmark_id:)
bookmark = bookmark_repo.fetch(id: bookmark_id)
bookmark.url

View File

@@ -4,7 +4,6 @@ module Admin
module Commands
module Movies
class Create
include Deps["repos.movie_repo"]
def call(movie)
@@ -20,8 +19,7 @@ module Admin
repo.create(movie)
end
end
end
end
end
end
end

View File

@@ -32,4 +32,4 @@ module Admin
end
end
end
end
end

View File

@@ -16,4 +16,4 @@ module Admin
end
end
end
end
end

View File

@@ -4,13 +4,12 @@ module Admin
module Repos
class PostRepo < Adamantium::Repo[:posts]
def tag_post(post_id:, tag_id:)
return if posts
.post_tags
.where(
post_id: post_id,
tag_id: tag_id
).count > 0
.post_tags
.where(
post_id: post_id,
tag_id: tag_id
).count > 0
posts
.post_tags
@@ -64,4 +63,4 @@ module Admin
end
end
end
end
end

View File

@@ -1,7 +1,6 @@
module Admin
module Repos
class PostTagRepo < Adamantium::Repo[:post_tags]
def merge_tags(target_id:, source_id:)
post_tags.where(tag_id: source_id).update(tag_id: target_id)
end

View File

@@ -6,6 +6,7 @@ module Admin
.order(Sequel.function(:lower, :label))
.to_a
end
def list_with_posts
tags
.combine(:posts)

View File

@@ -10,4 +10,4 @@ module Admin
attribute :label, Types::Coercible::String
end
end
end
end

View File

@@ -3,4 +3,4 @@ module Admin
config.layouts_dir = "layouts"
config.paths = "slices/admin/templates"
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Views
module AutoTagging
class Index < Admin::View
include Deps["repos.auto_tagging_repo"]
expose :auto_taggings do
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Views
module AutoTagging
class New < Admin::View
include Deps["repos.tag_repo"]
expose :tags do
@@ -15,4 +14,4 @@ module Admin
end
end
end
end
end

View File

@@ -4,7 +4,6 @@ module Admin
module Views
module Bookmarks
class Index < Admin::View
include Deps["repos.bookmark_repo"]
expose :published_bookmarks do |bookmarks|
@@ -16,7 +15,7 @@ module Admin
end
expose :bookmarks do
bookmark_repo.list.partition{|p| p.published_at }
bookmark_repo.list.partition { |p| p.published_at }
end
expose :running_jobs do
@@ -26,4 +25,4 @@ module Admin
end
end
end
end
end

View File

@@ -1,7 +1,6 @@
module Admin
module Views
class Index < Admin::View
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Views
module MergeTags
class Index < Admin::View
include Deps["repos.tag_repo"]
expose :tags do
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Views
module MergeTags
class New < Admin::View
include Deps["repos.tag_repo"]
expose :tag do |id:|
@@ -15,4 +14,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Views
module Photos
class Index < Admin::View
MEDIA_DIR = "public/media/".freeze
expose :photos_buckets do
@@ -13,4 +12,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Views
module Posts
class Index < Admin::View
include Deps["repos.post_repo"]
expose :published_posts do |posts|
@@ -14,9 +13,9 @@ module Admin
end
expose :posts do
post_repo.list.partition{|p| p.published_at }
post_repo.list.partition { |p| p.published_at }
end
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Views
module Tags
class Index < Admin::View
include Deps["repos.tag_repo"]
expose :tags do
@@ -10,13 +9,13 @@ module Admin
end
expose :unused_tags do |tags|
tags.partition {|t| t.posts.count == 0}.first
tags.partition { |t| t.posts.count == 0 }.first
end
expose :used_tags do |tags|
tags.partition {|t| t.posts.count == 0}.last
tags.partition { |t| t.posts.count == 0 }.last
end
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Views
module Trips
class Index < Admin::View
include Deps["repos.trip_repo"]
expose :trips do
@@ -11,4 +10,4 @@ module Admin
end
end
end
end
end

View File

@@ -8,4 +8,4 @@ module Admin
end
end
end
end
end

View File

@@ -2,7 +2,6 @@ module Admin
module Views
module Trips
class Show < Admin::View
include Deps["repos.trip_repo", "repos.post_repo"]
expose :trip do |id:|
@@ -15,4 +14,4 @@ module Admin
end
end
end
end
end

View File

@@ -1,15 +1,14 @@
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Adamantium::Geo::GpxParser do
subject { described_class.new }
let(:gpx_file) { File.join(SPEC_ROOT, "support", "fixtures", "geo.gpx") }
let(:expected_svg) { File.read(File.join(SPEC_ROOT, "support", "fixtures", "geo.svg")) }
let(:gpx_file) { File.join(SPEC_ROOT, "support", "fixtures", "geo.gpx") }
let(:expected_svg) { File.read(File.join(SPEC_ROOT, "support", "fixtures", "geo.svg")) }
it "parses a gpx file" do
# puts gpx_file.inspect
result = subject.call(path: gpx_file).value!
parsed_svg = Nokogiri::XML::Document.parse(result[:svg])
@@ -18,4 +17,4 @@ RSpec.describe Adamantium::Geo::GpxParser do
expect(result[:distance]).to eq 3.0724966849262554
expect(result[:duration]).to eq 15237.0
end
end
end

View File

@@ -24,4 +24,4 @@ Dir.glob(dist_path + "/*.{js,css}").each_with_object(filenames) do |f, memo|
File.rename(f, dist_path + "/" + filename + "-" + hash + File.extname(f))
end
File.open(folder_path + "/asset-manifest.json", "wb") {|f| f.write(JSON.generate(filenames)) }
File.binwrite(folder_path + "/asset-manifest.json", JSON.generate(filenames))