Class: RailsResponseDumper::Defined

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_response_dumper/defined.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Defined

Returns a new instance of Defined.



17
18
19
20
21
22
23
24
# File 'lib/rails_response_dumper/defined.rb', line 17

def initialize(name, &block)
  self.name = name
  self.klass = Class.new(ResponseDumper)

  instance_eval(&block)

  self.class.dumpers << self
end

Instance Attribute Details

#after_blockObject (readonly)

Returns the value of attribute after_block.



9
10
11
# File 'lib/rails_response_dumper/defined.rb', line 9

def after_block
  @after_block
end

#before_blockObject (readonly)

Returns the value of attribute before_block.



9
10
11
# File 'lib/rails_response_dumper/defined.rb', line 9

def before_block
  @before_block
end

#klassObject

Returns the value of attribute klass.



8
9
10
# File 'lib/rails_response_dumper/defined.rb', line 8

def klass
  @klass
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/rails_response_dumper/defined.rb', line 8

def name
  @name
end

Class Method Details

.dumpersObject



13
14
15
# File 'lib/rails_response_dumper/defined.rb', line 13

def self.dumpers
  @dumpers ||= []
end

Instance Method Details

#after(&block) ⇒ Object



38
39
40
# File 'lib/rails_response_dumper/defined.rb', line 38

def after(&block)
  @after_block = block
end

#before(&block) ⇒ Object



34
35
36
# File 'lib/rails_response_dumper/defined.rb', line 34

def before(&block)
  @before_block = block
end

#blocksObject



42
43
44
# File 'lib/rails_response_dumper/defined.rb', line 42

def blocks
  @blocks ||= []
end

#dump(name, status_codes: [:ok], &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/rails_response_dumper/defined.rb', line 26

def dump(name, status_codes: [:ok], &block)
  blocks << DumpBlock.new(
    name,
    status_codes.map { |status_code| Rack::Utils::SYMBOL_TO_STATUS_CODE[status_code] },
    block
  )
end

#reset_models(*models) ⇒ Object



46
47
48
49
# File 'lib/rails_response_dumper/defined.rb', line 46

def reset_models(*models)
  @reset_models ||= []
  @reset_models += models
end

#reset_models!Object



51
52
53
54
55
56
57
# File 'lib/rails_response_dumper/defined.rb', line 51

def reset_models!
  reset_models.each do |model|
    model.connection.exec_query <<~SQL.squish
      TRUNCATE #{model.quoted_table_name} RESTART IDENTITY CASCADE
    SQL
  end
end