Class: Shellfie::SessionConfig
- Inherits:
-
Object
- Object
- Shellfie::SessionConfig
- Defined in:
- lib/shellfie/session_config.rb
Constant Summary collapse
- MAX_BYTES =
1_048_576- MAX_DURATION =
86_400- MAX_COUNT =
10_000- MAX_CAPTURES =
100- MAX_PATTERN_LENGTH =
512- MAX_INCLUDE_FILES =
100- MAX_TOTAL_BYTES =
10 * MAX_BYTES
- ACTIONS =
%i[run type key sleep wait expect capture hide show].freeze
- STEP_OPTION_KEYS =
{ run: %i[visibility timeout async cwd], type: %i[speed], key: %i[count async timeout delay], sleep: [], wait: %i[timeout], expect: [], capture: [], hide: [], show: [] }.freeze
- TOP_LEVEL_KEYS =
%i[version mode title theme terminal requires steps outputs render redact vars step_sets].freeze
- TERMINAL_KEYS =
%i[shell columns rows cwd cwd_policy env env_allowlist timeout total_timeout prompt].freeze
- OUTPUT_KEYS =
%i[path format animate scale shadow transparent capture].freeze
- OUTPUT_FORMATS =
%w[png gif svg svg-raster webp apng mp4 webm png-sequence html txt ansi json asciicast cast].freeze
- RENDER_KEYS =
%i[window font animation headless].freeze
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#redactions ⇒ Object
readonly
Returns the value of attribute redactions.
-
#render ⇒ Object
readonly
Returns the value of attribute render.
-
#requires ⇒ Object
readonly
Returns the value of attribute requires.
-
#source_paths ⇒ Object
readonly
Returns the value of attribute source_paths.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#terminal ⇒ Object
readonly
Returns the value of attribute terminal.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #base_dir ⇒ Object
-
#initialize(raw, path: nil, source_paths: nil) ⇒ SessionConfig
constructor
A new instance of SessionConfig.
- #to_h ⇒ Object
Constructor Details
#initialize(raw, path: nil, source_paths: nil) ⇒ SessionConfig
Returns a new instance of SessionConfig.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/shellfie/session_config.rb', line 137 def initialize(raw, path: nil, source_paths: nil) raise ValidationError, "Session configuration must be a YAML mapping" unless raw.is_a?(Hash) unknown = raw.keys - TOP_LEVEL_KEYS raise_unknown_keys!(unknown, TOP_LEVEL_KEYS, "session") variables = validate_variables(raw[:vars] || {}) raw = interpolate_variables(raw.reject { |key, _value| key == :vars }, variables) raise ValidationError, "Session config version must be 2" unless raw[:version] == 2 raise ValidationError, "Session config must contain steps" unless raw.key?(:steps) raise ValidationError, "Session title must be a string" if raw.key?(:title) && !raw[:title].is_a?(String) @path = path @source_paths = Array(source_paths || path).compact.freeze @mode = (raw[:mode] || "run").to_s @title = (raw[:title] || "Terminal Session").to_s @theme = (raw[:theme] || "macos").to_s @terminal = defaults.merge(symbolize_hash(raw[:terminal] || {})) @requires = Array(raw[:requires]) raise ValidationError, "steps must be an array" unless raw[:steps].is_a?(Array) @steps = (raw[:steps], validate_step_sets(raw[:step_sets] || {})) @outputs = Array(raw[:outputs]).map { |output| symbolize_hash(output) } @render = symbolize_hash(raw[:render] || {}) %i[window font animation].each do |key| @render[key] = symbolize_hash(@render[key]) if @render[key].is_a?(Hash) end @redactions = Array(raw[:redact]) validate! end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def mode @mode end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def outputs @outputs end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def path @path end |
#redactions ⇒ Object (readonly)
Returns the value of attribute redactions.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def redactions @redactions end |
#render ⇒ Object (readonly)
Returns the value of attribute render.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def render @render end |
#requires ⇒ Object (readonly)
Returns the value of attribute requires.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def requires @requires end |
#source_paths ⇒ Object (readonly)
Returns the value of attribute source_paths.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def source_paths @source_paths end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def steps @steps end |
#terminal ⇒ Object (readonly)
Returns the value of attribute terminal.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def terminal @terminal end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def theme @theme end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
32 33 34 |
# File 'lib/shellfie/session_config.rb', line 32 def title @title end |
Class Method Details
.parse(path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/shellfie/session_config.rb', line 34 def self.parse(path) source_path = File.realpath(path) state = { files: 0, bytes: 0 } raw, documents, provenance = load_included(source_path, root: File.dirname(source_path), stack: [], state: state) new(raw, path: source_path, source_paths: documents.map(&:first).uniq) rescue ValidationError => e raise YamlSafety.annotate_validation_error(e, documents || [], provenance: provenance || {}) rescue Psych::Exception => e raise ParseError, "Invalid session YAML syntax: #{e.}" rescue Errno::ENOENT raise ParseError, "Session file not found: #{path}" end |
Instance Method Details
#base_dir ⇒ Object
166 167 168 |
# File 'lib/shellfie/session_config.rb', line 166 def base_dir path ? File.dirname(path) : Dir.pwd end |
#to_h ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/shellfie/session_config.rb', line 170 def to_h { version: 2, mode: mode, title: title, theme: theme, terminal: terminal, requires: requires, steps: steps, outputs: outputs, render: render, redact: redactions } end |