class LL::ListyList
Public Class Methods
new(cli: nil, name: nil)
click to toggle source
# File lib/ll/listy_list.rb, line 3 def initialize cli: nil, name: nil @checklists = [] @schemas = [] name ||= "listy-list".style :forestgreen, :bold @cli = cli @cli ||= VV::CLI.new name: name, version: LL::VERSION, argv: ARGV self.uri = "/" self.first_boot end
Public Instance Methods
await_input()
click to toggle source
# File lib/ll/listy_list.rb, line 195 def await_input @input = @cli.await_input message: "listy>" @input end
boot!() { || ... }
click to toggle source
# File lib/ll/listy_list.rb, line 29 def boot! @_status = :boot yield self.load end
boot?()
click to toggle source
# File lib/ll/listy_list.rb, line 191 def boot? self.status == :boot end
create_directories()
click to toggle source
# File lib/ll/listy_list.rb, line 221 def create_directories %w[ checklists schemas ].each do | _directory | directory = @cli.data_path.file_join _directory File.make_directory_if_not_exists directory end end
display()
click to toggle source
# File lib/ll/listy_list.rb, line 145 def display consider self.uri do puts self.uri given "/help" do @cli.print_help end given "/install" do directory = File.pwd.file_join "exe" @cli.install( executable_directory: directory ) end given "/version" do @cli.print_version end given "/unknown" do @cli.print_error command: @input end end end
first_boot()
click to toggle source
# File lib/ll/listy_list.rb, line 20 def first_boot self.create_directories self.boot! do self.show_help! if @cli.help? self.show_version! if @cli.version? end end
load()
click to toggle source
# File lib/ll/listy_list.rb, line 106 def load self.load_schemas self.load_checklists end
Also aliased as: reload
load_checklists()
click to toggle source
# File lib/ll/listy_list.rb, line 116 def load_checklists @checklists = LL::Checklist.load dir: @cli.data_path end
load_schemas()
click to toggle source
# File lib/ll/listy_list.rb, line 112 def load_schemas @schemas = LL::Schema.load dir: @cli.data_path end
lock()
click to toggle source
# File lib/ll/listy_list.rb, line 130 def lock File.write(lock_path, Process.pid.to_s) unless File.exists? lock_path return true if lock_contents == Process.pid.to_s fail "Unable to lock #{lock_path}, contains pid mismatch." end
lock_contents()
click to toggle source
ZACH WAS HERE: run ./bin/listy and hit lock error. Maybe
it was me assuming that a lock would have happened?
# File lib/ll/listy_list.rb, line 126 def lock_contents File.read(lock_path).chomp end
lock_path()
click to toggle source
# File lib/ll/listy_list.rb, line 120 def lock_path @cli.data_path.file_join "listy.lock" end
loop()
click to toggle source
# File lib/ll/listy_list.rb, line 35 def loop self.status = :loop unless shutdown? while loop? do self.load self.lock self.display self.await_input self.react self.persist self.unlock end self.shutdown ensure self.unlock end
loop?()
click to toggle source
# File lib/ll/listy_list.rb, line 187 def loop? self.status == :loop end
persist()
click to toggle source
# File lib/ll/listy_list.rb, line 170 def persist self.save_uri self.save_checklist self.save_schema_changes self.sync end
react()
click to toggle source
# File lib/ll/listy_list.rb, line 53 def react consider @input do given String.empty_string do self.uri = "/" end given "help" do self.uri = "/help" end given "install" do self.uri = "/install" end within %w[ version v ] do self.uri = "/version" end otherwise do self.uri = "/unknown" end end end
save_checklist()
click to toggle source
# File lib/ll/listy_list.rb, line 180 def save_checklist end
save_schema_changes()
click to toggle source
# File lib/ll/listy_list.rb, line 182 def save_schema_changes end
save_uri()
click to toggle source
TOOD: Implement these
# File lib/ll/listy_list.rb, line 178 def save_uri end
show_help!()
click to toggle source
# File lib/ll/listy_list.rb, line 79 def show_help! @cli.print_help self.shutdown! end
show_version()
click to toggle source
# File lib/ll/listy_list.rb, line 84 def show_version self.uri = "/version" @cli.print_version end
show_version!()
click to toggle source
# File lib/ll/listy_list.rb, line 89 def show_version! self.show_version self.shutdown! end
shutdown()
click to toggle source
# File lib/ll/listy_list.rb, line 94 def shutdown :shutdown_safely end
shutdown!()
click to toggle source
# File lib/ll/listy_list.rb, line 102 def shutdown! self.status = :shutdown end
shutdown?()
click to toggle source
# File lib/ll/listy_list.rb, line 98 def shutdown? self.status == :shutdown end
status()
click to toggle source
# File lib/ll/listy_list.rb, line 217 def status @_status end
status=(status)
click to toggle source
# File lib/ll/listy_list.rb, line 209 def status= status message = \ "Currently shutdown. Call `boot!` to return to resume." fail message if self.status == :shutdown %i[ loop boot pause shutdown ].includes! status @_status = status end
sync()
click to toggle source
# File lib/ll/listy_list.rb, line 184 def sync end
unlock()
click to toggle source
# File lib/ll/listy_list.rb, line 138 def unlock message = "Unable to unlock #{lock_path}, contains pid mismatch." fail message if lock_contents != Process.pid.to_s File.remove lock_path end
uri()
click to toggle source
# File lib/ll/listy_list.rb, line 205 def uri @_uri end
uri=(uri)
click to toggle source
Log this. Maybe incorporate into VV::CLI?
# File lib/ll/listy_list.rb, line 201 def uri= uri @_uri = uri end