Class: TypedDag::Configuration

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Configuration

Returns a new instance of Configuration.



23
24
25
# File 'lib/typed_dag/configuration.rb', line 23

def initialize(config)
  self.config = config
end

Class Method Details

.[](class_name) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/typed_dag/configuration.rb', line 8

def self.[](class_name)
  class_name = class_name.to_s

  @instances.detect do |config|
    config.node_class_name == class_name ||
      config.edge_class_name == class_name
  end
end

.eachObject



17
18
19
20
21
# File 'lib/typed_dag/configuration.rb', line 17

def self.each
  @instances.each do |instance|
    yield instance
  end
end

.set(config) ⇒ Object



2
3
4
5
6
# File 'lib/typed_dag/configuration.rb', line 2

def self.set(config)
  config = [config] unless config.is_a?(Array)

  @instances = config.map { |conf| new(conf) }
end

Instance Method Details

#count_columnObject



59
60
61
# File 'lib/typed_dag/configuration.rb', line 59

def count_column
  config[:count_column] || 'count'
end

#edge_classObject



43
44
45
# File 'lib/typed_dag/configuration.rb', line 43

def edge_class
  edge_class_name.constantize
end

#edge_class_nameObject



39
40
41
# File 'lib/typed_dag/configuration.rb', line 39

def edge_class_name
  config[:edge_class_name]
end

#edge_table_nameObject



47
48
49
# File 'lib/typed_dag/configuration.rb', line 47

def edge_table_name
  edge_class.table_name
end

#from_columnObject



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

def from_column
  config[:from_column] || 'from_id'
end

#node_classObject



31
32
33
# File 'lib/typed_dag/configuration.rb', line 31

def node_class
  node_class_name.constantize
end

#node_class_nameObject



27
28
29
# File 'lib/typed_dag/configuration.rb', line 27

def node_class_name
  config[:node_class_name]
end

#node_table_nameObject



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

def node_table_name
  node_class.table_name
end

#to_columnObject



55
56
57
# File 'lib/typed_dag/configuration.rb', line 55

def to_column
  config[:to_column] || 'to_id'
end

#type_columnsObject



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

def type_columns
  types.keys
end

#typesObject



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

def types
  config[:types] || default_types
end