Skip to content

Commit

Permalink
Move constants into a shoes.rb to start off shoes.rb as separate
Browse files Browse the repository at this point in the history
  • Loading branch information
noahgibbs committed Jul 11, 2023
1 parent 55775cf commit 796a172
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 38 deletions.
16 changes: 2 additions & 14 deletions lib/scarpe.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "shoes"

require_relative "scarpe/logger"

# This will never be triggered -- we use the (...) feature below, which means this
Expand All @@ -15,7 +17,6 @@
# Is there a Shoes::Error class? Should this be two different error classes?
class Scarpe::Error < StandardError; end

require_relative "scarpe/constants"
require_relative "scarpe/version"
require_relative "scarpe/promises"
require_relative "scarpe/display_service"
Expand All @@ -26,16 +27,3 @@ class Scarpe::Error < StandardError; end
d_s = ENV["SCARPE_DISPLAY_SERVICE"] || "wv_local"
# This is require, not require_relative, to allow gems to supply a new display service
require "scarpe/#{d_s}"

include Constants

module Shoes
class << self
def app(...)
app = Shoes::App.new(...)
app.init
app.run
app.destroy
end
end
end
24 changes: 0 additions & 24 deletions lib/scarpe/constants.rb

This file was deleted.

33 changes: 33 additions & 0 deletions lib/shoes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

# We're separating Shoes from Scarpe, a little at a time. This should eventually be requirable
# without using Scarpe at all.
#
# This Shoes gem will, if all goes well, be a lot like the old Shoes-core from Shoes4: a way
# to handle the DSL and command-line parts of Shoes without knowing anything about how the
# display side works at all.

# This will never be triggered -- we use the (...) feature below, which means this
# file won't even parse in old Rubies.
if RUBY_VERSION[0..2] < "3.2"
Scarpe::Logger.logger("Scarpe").error("Scarpe requires Ruby 3.2 or higher!")
exit(-1)
end

require_relative "shoes/constants"
module Kernel
include Shoes::Constants
end

class Shoes::Error < StandardError; end

module Shoes
class << self
def app(...)
app = Shoes::App.new(...)
app.init
app.run
app.destroy
end
end
end
26 changes: 26 additions & 0 deletions lib/shoes/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "tmpdir"

module Shoes
module Constants
def self.find_lib_dir
homes = [
[ENV["LOCALAPPDATA"], "Shoes"],
[ENV["APPDATA"], "Shoes"],
[ENV["HOME"], ".shoes"],
[Dir.tmpdir, "shoes"],
]
top, file = homes.detect { |home_top, _| home_top && File.exist?(home_top) }
File.join(top, file)
end

LIB_DIR = find_lib_dir

# Math constants from Shoes3
RAD2PI = 0.01745329251994329577
TWO_PI = 6.28318530717958647693
HALF_PI = 1.57079632679489661923
PI = 3.14159265358979323846
end
end

0 comments on commit 796a172

Please sign in to comment.