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
- #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_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
Returns a new instance of 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
154 155 156 157 |
# File 'lib/ll/listy_list.rb', line 154 def await_input input = @cli.await_input message: "hi" 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
150 151 152 |
# File 'lib/ll/listy_list.rb', line 150 def boot? self.status == :boot end |
#create_directories ⇒ Object
180 181 182 183 184 185 |
# File 'lib/ll/listy_list.rb', line 180 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
125 126 127 |
# File 'lib/ll/listy_list.rb', line 125 def display puts :display 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
88 89 90 91 |
# File 'lib/ll/listy_list.rb', line 88 def load self.load_schemas self.load_checklists end |
#load_checklists ⇒ Object
98 99 100 |
# File 'lib/ll/listy_list.rb', line 98 def load_checklists @checklists = LL::Checklist.load dir: @cli.data_path end |
#load_schemas ⇒ Object
94 95 96 |
# File 'lib/ll/listy_list.rb', line 94 def load_schemas @schemas = LL::Schema.load dir: @cli.data_path end |
#lock ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/ll/listy_list.rb', line 110 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
106 107 108 |
# File 'lib/ll/listy_list.rb', line 106 def lock_contents File.read(lock_path).chomp end |
#lock_path ⇒ Object
102 103 104 |
# File 'lib/ll/listy_list.rb', line 102 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
146 147 148 |
# File 'lib/ll/listy_list.rb', line 146 def loop? self.status == :loop end |
#persist ⇒ Object
129 130 131 132 133 134 |
# File 'lib/ll/listy_list.rb', line 129 def persist self.save_uri self.save_checklist self.save_schema_changes self.sync end |
#react ⇒ Object
53 54 |
# File 'lib/ll/listy_list.rb', line 53 def react end |
#save_checklist ⇒ Object
139 140 |
# File 'lib/ll/listy_list.rb', line 139 def save_checklist end |
#save_schema_changes ⇒ Object
141 142 |
# File 'lib/ll/listy_list.rb', line 141 def save_schema_changes end |
#save_uri ⇒ Object
TOOD: Implement these
137 138 |
# File 'lib/ll/listy_list.rb', line 137 def save_uri end |
#show_help ⇒ Object
56 57 58 59 |
# File 'lib/ll/listy_list.rb', line 56 def show_help self.uri = "/help" @cli.print_help end |
#show_help! ⇒ Object
61 62 63 64 |
# File 'lib/ll/listy_list.rb', line 61 def show_help! self.show_help self.shutdown! end |
#show_version ⇒ Object
66 67 68 69 |
# File 'lib/ll/listy_list.rb', line 66 def show_version self.uri = "/version" @cli.print_version end |
#show_version! ⇒ Object
71 72 73 74 |
# File 'lib/ll/listy_list.rb', line 71 def show_version! self.show_version self.shutdown! end |
#shutdown ⇒ Object
76 77 78 |
# File 'lib/ll/listy_list.rb', line 76 def shutdown :shutdown_safely end |
#shutdown! ⇒ Object
84 85 86 |
# File 'lib/ll/listy_list.rb', line 84 def shutdown! self.status = :shutdown end |
#shutdown? ⇒ Boolean
80 81 82 |
# File 'lib/ll/listy_list.rb', line 80 def shutdown? self.status == :shutdown end |
#status ⇒ Object
176 177 178 |
# File 'lib/ll/listy_list.rb', line 176 def status @_status end |
#status=(status) ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/ll/listy_list.rb', line 168 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
143 144 |
# File 'lib/ll/listy_list.rb', line 143 def sync end |
#unlock ⇒ Object
118 119 120 121 122 123 |
# File 'lib/ll/listy_list.rb', line 118 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
164 165 166 |
# File 'lib/ll/listy_list.rb', line 164 def uri @_uri end |
#uri=(uri) ⇒ Object
Log this. Maybe incorporate into VV::CLI?
160 161 162 |
# File 'lib/ll/listy_list.rb', line 160 def uri= uri @_uri = uri end |