Class: Optimize::Demo::Walkthrough

Inherits:
Object
  • Object
show all
Defined in:
lib/optimize/demo/walkthrough.rb

Defined Under Namespace

Classes: InvalidSidecar

Constant Summary collapse

REQUIRED_FIELDS =
%w[fixture entry_setup entry_call walkthrough].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sidecar_path:, fixture:, entry_setup:, entry_call:, walkthrough:) ⇒ Walkthrough

Returns a new instance of Walkthrough.



39
40
41
42
43
44
45
# File 'lib/optimize/demo/walkthrough.rb', line 39

def initialize(sidecar_path:, fixture:, entry_setup:, entry_call:, walkthrough:)
  @sidecar_path = sidecar_path
  @fixture = fixture
  @entry_setup = entry_setup
  @entry_call = entry_call
  @walkthrough = walkthrough
end

Instance Attribute Details

#entry_callObject (readonly)

Returns the value of attribute entry_call.



13
14
15
# File 'lib/optimize/demo/walkthrough.rb', line 13

def entry_call
  @entry_call
end

#entry_setupObject (readonly)

Returns the value of attribute entry_setup.



13
14
15
# File 'lib/optimize/demo/walkthrough.rb', line 13

def entry_setup
  @entry_setup
end

#fixtureObject (readonly)

Returns the value of attribute fixture.



13
14
15
# File 'lib/optimize/demo/walkthrough.rb', line 13

def fixture
  @fixture
end

#sidecar_pathObject (readonly)

Returns the value of attribute sidecar_path.



13
14
15
# File 'lib/optimize/demo/walkthrough.rb', line 13

def sidecar_path
  @sidecar_path
end

#walkthroughObject (readonly)

Returns the value of attribute walkthrough.



13
14
15
# File 'lib/optimize/demo/walkthrough.rb', line 13

def walkthrough
  @walkthrough
end

Class Method Details

.load(path) ⇒ Object

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/optimize/demo/walkthrough.rb', line 15

def self.load(path)
  data = Psych.safe_load_file(path, permitted_classes: [])
  raise InvalidSidecar, "sidecar is not a mapping: #{path}" unless data.is_a?(Hash)

  missing = REQUIRED_FIELDS - data.keys
  raise InvalidSidecar, "missing fields #{missing.inspect} in #{path}" unless missing.empty?

  wt_names = Array(data["walkthrough"]).map(&:to_sym)
  valid = Pipeline.default.passes.map(&:name)
  unknown = wt_names - valid
  unless unknown.empty?
    raise InvalidSidecar,
          "unknown pass name(s) in #{path}: #{unknown.inspect}; valid: #{valid.inspect}"
  end

  new(
    sidecar_path: path,
    fixture: data["fixture"],
    entry_setup: data["entry_setup"].to_s,
    entry_call: data["entry_call"],
    walkthrough: wt_names,
  )
end

Instance Method Details

#fixture_pathObject



47
48
49
# File 'lib/optimize/demo/walkthrough.rb', line 47

def fixture_path
  File.expand_path(@fixture, File.dirname(@sidecar_path))
end