Class: VcrStripeWebhook::EventCassette::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/vcr_stripe_webhook/event_cassette.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events: [], waits: []) ⇒ Data

Returns a new instance of Data.



132
133
134
135
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 132

def initialize(events: [], waits: [])
  @events = events
  @waits = waits
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



130
131
132
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 130

def events
  @events
end

#waitsObject (readonly)

Returns the value of attribute waits.



130
131
132
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 130

def waits
  @waits
end

Class Method Details

.deserialize(path) ⇒ Object



147
148
149
150
151
152
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 147

def deserialize(path)
  yaml = YAML.safe_load_file(path, permitted_classes: [])
  events = yaml["events"].map { |event_hash| Event.from_hash(event_hash) }
  waits = yaml["waits"].map { |hash| Wait.from_hash(hash) }
  Data.new(events: events, waits: waits)
end

Instance Method Details

#serialize(path) ⇒ Object



137
138
139
140
141
142
143
144
# File 'lib/vcr_stripe_webhook/event_cassette.rb', line 137

def serialize(path)
  yaml = YAML.dump({
                     "events" => @events.map(&:to_h),
                     "waits" => @waits.map(&:to_h)
                   })
  FileUtils.mkdir_p File.dirname(path)
  File.write(path, yaml)
end