Class: LL::ListyList
- Inherits:
-
Object
- Object
- LL::ListyList
- Defined in:
- lib/ll/listy_list.rb
Instance Method Summary collapse
- #await_input ⇒ Object
- #boot! ⇒ Object
- #boot? ⇒ Boolean
- #create_directories ⇒ Object
- #display ⇒ Object
- #first_boot ⇒ Object
-
#initialize(cli: nil, name: nil) ⇒ ListyList
constructor
A new instance of ListyList.
- #load ⇒ Object (also: #reload)
- #load_checklists ⇒ Object
- #load_schemas ⇒ Object
- #lock ⇒ Object
-
#lock_contents ⇒ Object
ZACH WAS HERE: run ./bin/listy and hit lock error.
- #lock_path ⇒ Object
- #loop ⇒ Object
- #loop? ⇒ Boolean
- #persist ⇒ Object
- #react ⇒ Object
- #save_checklist ⇒ Object
- #save_schema_changes ⇒ Object
-
#save_uri ⇒ Object
TOOD: Implement these.
- #show_help! ⇒ Object
- #show_version ⇒ Object
- #show_version! ⇒ Object
- #shutdown ⇒ Object
- #shutdown! ⇒ Object
- #shutdown? ⇒ Boolean
- #status ⇒ Object
- #status=(status) ⇒ Object
- #sync ⇒ Object
- #unlock ⇒ Object
- #uri ⇒ Object
-
#uri=(uri) ⇒ Object
Log this.
Constructor Details
#initialize(cli: nil, name: nil) ⇒ ListyList
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Method Details
#await_input ⇒ Object
195 196 197 198 |
# File 'lib/ll/listy_list.rb', line 195 def await_input @input = @cli.await_input message: "listy>" @input end |
#boot! ⇒ Object
29 30 31 32 33 |
# File 'lib/ll/listy_list.rb', line 29 def boot! @_status = :boot yield self.load end |
#boot? ⇒ Boolean
191 192 193 |
# File 'lib/ll/listy_list.rb', line 191 def boot? self.status == :boot end |
#create_directories ⇒ Object
221 222 223 224 225 226 |
# 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 ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# 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 ⇒ Object
20 21 22 23 24 25 26 27 |
# 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 ⇒ Object Also known as: reload
106 107 108 109 |
# File 'lib/ll/listy_list.rb', line 106 def load self.load_schemas self.load_checklists end |
#load_checklists ⇒ Object
116 117 118 |
# File 'lib/ll/listy_list.rb', line 116 def load_checklists @checklists = LL::Checklist.load dir: @cli.data_path end |
#load_schemas ⇒ Object
112 113 114 |
# File 'lib/ll/listy_list.rb', line 112 def load_schemas @schemas = LL::Schema.load dir: @cli.data_path end |
#lock ⇒ Object
130 131 132 133 134 135 136 |
# 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 ⇒ Object
ZACH WAS HERE: run ./bin/listy and hit lock error. Maybe
it was me assuming that a lock would have happened?
126 127 128 |
# File 'lib/ll/listy_list.rb', line 126 def lock_contents File.read(lock_path).chomp end |
#lock_path ⇒ Object
120 121 122 |
# File 'lib/ll/listy_list.rb', line 120 def lock_path @cli.data_path.file_join "listy.lock" end |
#loop ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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? ⇒ Boolean
187 188 189 |
# File 'lib/ll/listy_list.rb', line 187 def loop? self.status == :loop end |
#persist ⇒ Object
170 171 172 173 174 175 |
# File 'lib/ll/listy_list.rb', line 170 def persist self.save_uri self.save_checklist self.save_schema_changes self.sync end |
#react ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# 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 ⇒ Object
180 181 |
# File 'lib/ll/listy_list.rb', line 180 def save_checklist end |
#save_schema_changes ⇒ Object
182 183 |
# File 'lib/ll/listy_list.rb', line 182 def save_schema_changes end |
#save_uri ⇒ Object
TOOD: Implement these
178 179 |
# File 'lib/ll/listy_list.rb', line 178 def save_uri end |
#show_help! ⇒ Object
79 80 81 82 |
# File 'lib/ll/listy_list.rb', line 79 def show_help! @cli.print_help self.shutdown! end |
#show_version ⇒ Object
84 85 86 87 |
# File 'lib/ll/listy_list.rb', line 84 def show_version self.uri = "/version" @cli.print_version end |
#show_version! ⇒ Object
89 90 91 92 |
# File 'lib/ll/listy_list.rb', line 89 def show_version! self.show_version self.shutdown! end |
#shutdown ⇒ Object
94 95 96 |
# File 'lib/ll/listy_list.rb', line 94 def shutdown :shutdown_safely end |
#shutdown! ⇒ Object
102 103 104 |
# File 'lib/ll/listy_list.rb', line 102 def shutdown! self.status = :shutdown end |
#shutdown? ⇒ Boolean
98 99 100 |
# File 'lib/ll/listy_list.rb', line 98 def shutdown? self.status == :shutdown end |
#status ⇒ Object
217 218 219 |
# File 'lib/ll/listy_list.rb', line 217 def status @_status end |
#status=(status) ⇒ Object
209 210 211 212 213 214 215 |
# File 'lib/ll/listy_list.rb', line 209 def status= status = \ "Currently shutdown. Call `boot!` to return to resume." fail if self.status == :shutdown %i[ loop boot pause shutdown ].includes! status @_status = status end |
#sync ⇒ Object
184 185 |
# File 'lib/ll/listy_list.rb', line 184 def sync end |
#unlock ⇒ Object
138 139 140 141 142 143 |
# File 'lib/ll/listy_list.rb', line 138 def unlock = "Unable to unlock #{lock_path}, contains pid mismatch." fail if lock_contents != Process.pid.to_s File.remove lock_path end |
#uri ⇒ Object
205 206 207 |
# File 'lib/ll/listy_list.rb', line 205 def uri @_uri end |
#uri=(uri) ⇒ Object
Log this. Maybe incorporate into VV::CLI?
201 202 203 |
# File 'lib/ll/listy_list.rb', line 201 def uri= uri @_uri = uri end |