Class: DagMe::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/dag_me/configuration.rb

Constant Summary collapse

MAINTAIN_MODES =
%i[postgresql_closure recursive_cte].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#edge_tableObject (readonly)

Returns the value of attribute edge_table.



7
8
9
# File 'lib/dag_me/configuration.rb', line 7

def edge_table
  @edge_table
end

#maintainObject (readonly)

Returns the value of attribute maintain.



7
8
9
# File 'lib/dag_me/configuration.rb', line 7

def maintain
  @maintain
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/dag_me/configuration.rb', line 7

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/dag_me/configuration.rb', line 7

def name
  @name
end

#paths_tableObject (readonly)

Returns the value of attribute paths_table.



7
8
9
# File 'lib/dag_me/configuration.rb', line 7

def paths_table
  @paths_table
end

#prefixObject (readonly)

Returns the value of attribute prefix.



7
8
9
# File 'lib/dag_me/configuration.rb', line 7

def prefix
  @prefix
end

#schemaObject (readonly)

Returns the value of attribute schema.



7
8
9
# File 'lib/dag_me/configuration.rb', line 7

def schema
  @schema
end

#scope_columnsObject (readonly)

Returns the value of attribute scope_columns.



7
8
9
# File 'lib/dag_me/configuration.rb', line 7

def scope_columns
  @scope_columns
end

Instance Method Details

#adapterObject



134
135
136
137
138
139
140
# File 'lib/dag_me/configuration.rb', line 134

def adapter
  @adapter ||= if closure?
                 Adapters::PostgresqlClosure.new(self)
               else
                 Adapters::RecursiveCte.new(self)
               end
end

#association_name(base) ⇒ Object

children / power_children, dag_child_edges / power_dag_child_edges, ...



80
81
82
# File 'lib/dag_me/configuration.rb', line 80

def association_name(base)
  default? ? base.to_sym : :"#{name}_#{base}"
end

#closure?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/dag_me/configuration.rb', line 35

def closure?
  maintain == :postgresql_closure
end

#composite_pk?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/dag_me/configuration.rb', line 84

def composite_pk?
  @composite_pk
end

#default?Boolean

The unnamed dag from a bare dag_me call. Named dags come from dag_me :power and get name-prefixed tables, constants, and associations so several graphs can coexist on one model.

Returns:

  • (Boolean)


58
59
60
# File 'lib/dag_me/configuration.rb', line 58

def default?
  name.nil?
end

#edge_child_columnsObject



114
115
116
# File 'lib/dag_me/configuration.rb', line 114

def edge_child_columns
  @edge_child_columns ||= role_columns('child')
end

#edge_classObject



71
72
73
# File 'lib/dag_me/configuration.rb', line 71

def edge_class
  model.const_get(edge_class_name)
end

#edge_class_nameObject

Task::DagEdge for the default dag, Relay::PowerDagEdge for dag_me :power.



63
64
65
# File 'lib/dag_me/configuration.rb', line 63

def edge_class_name
  default? ? 'DagEdge' : "#{name.to_s.camelize}DagEdge"
end

#edge_parent_columnsObject

Graph column names, one per pk column. Single-key models keep the classic parent_id / child_id / ancestor_id / descendant_id regardless of the pk's actual name; composite keys suffix each key column.



110
111
112
# File 'lib/dag_me/configuration.rb', line 110

def edge_parent_columns
  @edge_parent_columns ||= role_columns('parent')
end

#function_ref(suffix) ⇒ Object

Schema-qualified reference for a generated function ("ai.skill_dag_lock").



46
47
48
# File 'lib/dag_me/configuration.rb', line 46

def function_ref(suffix)
  qualify("#{prefix}_#{suffix}")
end

#node_pk_columnsObject

Node identity as an ordered column list. Single-key models yield one column and everything downstream degenerates to the classic layout.



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dag_me/configuration.rb', line 94

def node_pk_columns
  @node_pk_columns ||= if composite_pk?
                         model.primary_key.map(&:to_s).freeze
                       else
                         pk = model.primary_key
                         if pk.is_a?(Array)
                           raise ArgumentError,
                                 "#{model.name}: declare `self.primary_key = [...]` before calling dag_me"
                         end
                         [pk.to_s].freeze
                       end
end

#node_pk_type(column) ⇒ Object



126
127
128
# File 'lib/dag_me/configuration.rb', line 126

def node_pk_type(column)
  model.columns_hash.fetch(column.to_s).sql_type
end

#node_tableObject



88
89
90
# File 'lib/dag_me/configuration.rb', line 88

def node_table
  model.table_name
end

#paths_ancestor_columnsObject



118
119
120
# File 'lib/dag_me/configuration.rb', line 118

def paths_ancestor_columns
  @paths_ancestor_columns ||= role_columns('ancestor')
end

#paths_classObject



75
76
77
# File 'lib/dag_me/configuration.rb', line 75

def paths_class
  model.const_get(paths_class_name)
end

#paths_class_nameObject



67
68
69
# File 'lib/dag_me/configuration.rb', line 67

def paths_class_name
  default? ? 'DagPath' : "#{name.to_s.camelize}DagPath"
end

#paths_descendant_columnsObject



122
123
124
# File 'lib/dag_me/configuration.rb', line 122

def paths_descendant_columns
  @paths_descendant_columns ||= role_columns('descendant')
end

#qualify(identifier) ⇒ Object

"skill_dag_edges" -> "ai.skill_dag_edges" when the node table lives in a named schema; identity otherwise.



41
42
43
# File 'lib/dag_me/configuration.rb', line 41

def qualify(identifier)
  schema ? "#{schema}.#{identifier}" : identifier
end

#scope_column_type(column) ⇒ Object



130
131
132
# File 'lib/dag_me/configuration.rb', line 130

def scope_column_type(column)
  model.columns_hash.fetch(column.to_s).sql_type
end

#trigger_name(suffix) ⇒ Object

Trigger names are plain identifiers; placement comes from ON

.



51
52
53
# File 'lib/dag_me/configuration.rb', line 51

def trigger_name(suffix)
  "#{prefix}_#{suffix}"
end