Class: Postspec::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/postspec/frame.rb

Overview

TODO: Add #stack and forward #postspec to it

Direct Known Subclasses

EmptyFrame, FoxFrame, NopFrame, SeedFrame

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(postspec, parent, search_path, push_sql, pop_sql, ids, fox_anchors) ⇒ Frame

Returns a new instance of Frame.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/postspec/frame.rb', line 39

def initialize(postspec, parent, search_path, push_sql, pop_sql, ids, fox_anchors)
  constrain postspec, Postspec
  constrain parent, NilClass, Frame
  constrain search_path, [String], NilClass
  constrain push_sql, String, [String], NilClass
  constrain pop_sql, String, [String], NilClass
  constrain ids, { String => Integer }
  constrain fox_anchors, FixtureFox::Anchors, NilClass
  @postspec = postspec
  @parent = parent
  @search_path = search_path || %w(public)
  @push_sql = ["set search_path to #{@search_path.join(", ")}"] + Array(push_sql || [])
  @pop_sql = Array(pop_sql || []) + (parent ? ["set search_path to #{parent.search_path.join(", ")}"] : [])
  @ids = ids || {}
  @fox_anchors = fox_anchors || FixtureFox::Anchors.new(@postspec.type)
  anchors = @fox_anchors.values.map { |anchor| [anchor.name, anchor.id] }.to_h
  @anchors = (parent ? parent.anchors.merge(anchors) : anchors)
end

Instance Attribute Details

#anchorsObject (readonly)

Returns the value of attribute anchors.



37
38
39
# File 'lib/postspec/frame.rb', line 37

def anchors
  @anchors
end

#idsObject (readonly)

Returns the value of attribute ids.



36
37
38
# File 'lib/postspec/frame.rb', line 36

def ids
  @ids
end

#parentObject (readonly)

Returns the value of attribute parent.



30
31
32
# File 'lib/postspec/frame.rb', line 30

def parent
  @parent
end

#pop_sqlObject (readonly)

Returns the value of attribute pop_sql.



35
36
37
# File 'lib/postspec/frame.rb', line 35

def pop_sql
  @pop_sql
end

#postspecObject (readonly)

Returns the value of attribute postspec.



29
30
31
# File 'lib/postspec/frame.rb', line 29

def postspec
  @postspec
end

#push_sqlObject (readonly)

Returns the value of attribute push_sql.



34
35
36
# File 'lib/postspec/frame.rb', line 34

def push_sql
  @push_sql
end

#search_pathObject (readonly)

Returns the value of attribute search_path.



31
32
33
# File 'lib/postspec/frame.rb', line 31

def search_path
  @search_path
end

Instance Method Details

#dumpObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/postspec/frame.rb', line 61

def dump()
  puts self.class
  indent {
    puts "search_path: #{search_path}"
    puts "push_sql:"
    indent { puts push_sql }
    puts "pop:sql:"
    indent { puts pop_sql }
  }
end

#schemaObject



32
# File 'lib/postspec/frame.rb', line 32

def schema() @search_path.first end

#transaction?Boolean

Returns true if this frame is associated with a transaction

Returns:

  • (Boolean)


59
# File 'lib/postspec/frame.rb', line 59

def transaction?() true end