Class: LL::Checklist
- Inherits:
-
Object
- Object
- LL::Checklist
- Defined in:
- lib/ll/checklist.rb
Instance Attribute Summary collapse
-
#action_at ⇒ Object
readonly
Returns the value of attribute action_at.
-
#authority ⇒ Object
readonly
Returns the value of attribute authority.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#document_version ⇒ Object
readonly
Returns the value of attribute document_version.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#serialization_identifier ⇒ Object
readonly
Returns the value of attribute serialization_identifier.
-
#steps ⇒ Object
Returns the value of attribute steps.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #current_version ⇒ Object
- #document_current? ⇒ Boolean
-
#initialize(document: nil, name: nil, authority: nil) {|_self| ... } ⇒ Checklist
constructor
Maybe abstract the versioning here into VV?.
- #kind ⇒ Object
- #meta=(meta) ⇒ Object
- #parse_document!(document) ⇒ Object
- #reformat! ⇒ Object
- #supported_versions ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #vv_json ⇒ Object
Constructor Details
#initialize(document: nil, name: nil, authority: nil) {|_self| ... } ⇒ Checklist
Maybe abstract the versioning here into VV?
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ll/checklist.rb', line 21 def initialize document: nil, name: nil, authority: nil @name = name @name ||= "Prototypical" @authority = @authority ||= LL. @document_version = nil self.parse_document! document if document yield self if block_given? self.reformat! unless self.document_current? end |
Instance Attribute Details
#action_at ⇒ Object (readonly)
Returns the value of attribute action_at.
3 4 5 |
# File 'lib/ll/checklist.rb', line 3 def action_at @action_at end |
#authority ⇒ Object (readonly)
Returns the value of attribute authority.
3 4 5 |
# File 'lib/ll/checklist.rb', line 3 def @authority end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/ll/checklist.rb', line 3 def description @description end |
#document_version ⇒ Object (readonly)
Returns the value of attribute document_version.
3 4 5 |
# File 'lib/ll/checklist.rb', line 3 def document_version @document_version end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
3 4 5 |
# File 'lib/ll/checklist.rb', line 3 def identifier @identifier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/ll/checklist.rb', line 3 def name @name end |
#serialization_identifier ⇒ Object (readonly)
Returns the value of attribute serialization_identifier.
3 4 5 |
# File 'lib/ll/checklist.rb', line 3 def serialization_identifier @serialization_identifier end |
#steps ⇒ Object
Returns the value of attribute steps.
3 4 5 |
# File 'lib/ll/checklist.rb', line 3 def steps @steps end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/ll/checklist.rb', line 3 def title @title end |
Class Method Details
.load(dir:) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/ll/checklist.rb', line 13 def self.load( dir: ) filepaths = Dir.glob(File.join dir, "checklists/*") filepaths.each do | filepath | self.new File.read filepath end end |
Instance Method Details
#current_version ⇒ Object
78 79 80 |
# File 'lib/ll/checklist.rb', line 78 def current_version LL::VERSION end |
#document_current? ⇒ Boolean
51 52 53 54 55 |
# File 'lib/ll/checklist.rb', line 51 def document_current? return nil if @document_version.nil? @document_version == self.current_version end |
#kind ⇒ Object
88 89 90 |
# File 'lib/ll/checklist.rb', line 88 def kind "checklist" end |
#meta=(meta) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ll/checklist.rb', line 92 def .symbolize_keys! = .fetch :authority = .fetch :version = .fetch :kind = .fetch :format = == self. = "Document authority `#{}` unknown." fail unless format_ok = == "json" = \ "Document format `#{}` not supported, must be `json`." fail unless format_ok version_ok = .one_of?( *supported_versions ) = "Document version `#{}` not supported." fail unless version_ok kind_ok = == "checklist" = \ "Document kind `#{}` not supported, must be `checklist`." fail unless kind_ok @document_version = end |
#parse_document!(document) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ll/checklist.rb', line 57 def parse_document! document if document.is_a? String document = document.parse_json elsif document.is_a? Hash else fail TypeError, "Checklist expects string or hash document" end document.symbolize_keys! attrs = %i[ meta title description identifier serialization_identifier action_at steps ] self.set_attrs_via attrs, document: document end |
#reformat! ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ll/checklist.rb', line 39 def reformat! @document_version = self.current_version # Because the same checklist may be serialized multiple times, # by different clients it will get tricky tracing problems, so # we include an identifier that clients should generate, but never # manipulate. @serialization_identifier = Random.identifier self.steps end |
#supported_versions ⇒ Object
82 83 84 85 86 |
# File 'lib/ll/checklist.rb', line 82 def supported_versions %w[ 0.0.2 0.0.3 0.0.4 ] end |
#to_h ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ll/checklist.rb', line 132 def to_h = \ "Checklist in indeterminate state. This should never happen." fail unless self.document_current? format = "hash" = { version: self.current_version, kind: self.kind, authority: self., format: format } { meta: , title: self.title, description: self.description, identifier: self.identifier, serialization_identifier: self.serialization_identifier, action_at: self.action_at, steps: self.steps } end |
#to_s ⇒ Object
128 129 130 |
# File 'lib/ll/checklist.rb', line 128 def to_s "Checklist: #{self.name}" end |
#vv_json ⇒ Object
152 153 154 155 156 157 |
# File 'lib/ll/checklist.rb', line 152 def vv_json format = "json" response = self.to_h response[:meta][:format] = format response.vv_json end |