It hasn't been necessary to use create_with_id since
ebc79622df
, in December 2024.
I have plans to introduce:
```ruby
def create_with_id(id, values)
obj = new(values)
obj.id = id
obj.save_changes
end
```
This will make it easier to use the same id when creating
multiple objects. The first step is removing the existing
uses of create_with_id.
95 lines
2.1 KiB
Ruby
Executable File
95 lines
2.1 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
||
# frozen_string_literal: true
|
||
|
||
REPL = true
|
||
|
||
require_relative "../loader"
|
||
|
||
if Config.production? && ENV["INGEST_KEY"].nil?
|
||
puts "INGEST_KEY is not set in production environment. This is not allowed for auditing purposes."
|
||
exit(1)
|
||
end
|
||
|
||
require "pry"
|
||
|
||
if Config.development?
|
||
require "awesome_print"
|
||
require "awesome_print/ext/sequel"
|
||
|
||
module AwesomePrint::Sequel
|
||
remove_method(:awesome_sequel_document)
|
||
def awesome_sequel_document(object)
|
||
"#{object} #{awesome_hash(object.values)}"
|
||
end
|
||
end
|
||
end
|
||
|
||
def dev_project
|
||
return unless Config.development?
|
||
ac = Account[email: "dev@ubicloud.com"] || Account.create(email: "dev@ubicloud.com")
|
||
ac.projects.first || ac.create_project_with_default_policy("default")
|
||
end
|
||
|
||
def udec(*)
|
||
UBID.decode(*)
|
||
end
|
||
|
||
opts = Pry::CLI.parse_options
|
||
Pry.config.prompt_name = if Config.production?
|
||
"\e[41m⚠️ %s\e[0m" % "clover-#{Config.rack_env}"
|
||
else
|
||
"clover-#{Config.rack_env}"
|
||
end
|
||
|
||
if Config.development?
|
||
module PryReloader
|
||
def evaluate_ruby(code)
|
||
begin
|
||
Unreloader.reload!
|
||
rescue StandardError, ScriptError => e
|
||
puts "#{e.class}: #{e.message}"
|
||
puts e.backtrace[0...5]
|
||
end
|
||
|
||
super
|
||
end
|
||
end
|
||
Pry.prepend(PryReloader)
|
||
end
|
||
|
||
if ENV["INGEST_KEY"]
|
||
PRY_LOGGER = LogDnaBatcher.new(ENV["INGEST_KEY"])
|
||
|
||
module PryLogger
|
||
def evaluate_ruby(code)
|
||
@counter ||= 0
|
||
@counter += 1
|
||
|
||
PRY_LOGGER.log("$> #{code.strip}", app: "pry", level: "info", type: "pry_input", counter: @counter)
|
||
|
||
# Evaluate and capture result
|
||
begin
|
||
result = super
|
||
|
||
# Log output
|
||
output = result.inspect
|
||
output = "#{output[0..500]}..." if output.length > 500
|
||
PRY_LOGGER.log(output, app: "pry", level: "info", type: "pry_output", counter: @counter)
|
||
|
||
result
|
||
rescue => e
|
||
PRY_LOGGER.log("#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}", app: "pry", level: "error", type: "eval_error", counter: @counter)
|
||
raise
|
||
end
|
||
end
|
||
end
|
||
|
||
at_exit do
|
||
PRY_LOGGER.stop
|
||
end
|
||
|
||
Pry.prepend(PryLogger)
|
||
end
|
||
|
||
Pry::CLI.start(opts)
|