Class: TableSaw::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/table_saw/manifest.rb

Defined Under Namespace

Classes: HasManyEntry, Table

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Manifest

Returns a new instance of Manifest.



74
75
76
# File 'lib/table_saw/manifest.rb', line 74

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



72
73
74
# File 'lib/table_saw/manifest.rb', line 72

def config
  @config
end

Class Method Details

.instanceObject

Raises:

  • (ArgumentError)


66
67
68
69
70
# File 'lib/table_saw/manifest.rb', line 66

def self.instance
  raise ArgumentError, 'Could not find manifest file' unless File.exist?(TableSaw.configuration.manifest)

  new(YAML.safe_load_file(TableSaw.configuration.manifest))
end

Instance Method Details

#associationsObject



99
100
101
# File 'lib/table_saw/manifest.rb', line 99

def associations
  @associations ||= TableSaw::Associations.new(self)
end

#foreign_keysObject



95
96
97
# File 'lib/table_saw/manifest.rb', line 95

def foreign_keys
  @foreign_keys ||= config.fetch('foreign_keys', [])
end

#has_manyObject



89
90
91
92
93
# File 'lib/table_saw/manifest.rb', line 89

def has_many
  @has_many ||= config.fetch('has_many', {}).transform_values do |value|
    HasManyEntry.build(value)
  end
end

#tablesObject



83
84
85
86
87
# File 'lib/table_saw/manifest.rb', line 83

def tables
  @tables ||= config['tables'].map { |entry| Table.new(variables, entry) }.each_with_object({}) do |t, memo|
    memo[t.name] = t
  end
end

#variablesObject



78
79
80
81
# File 'lib/table_saw/manifest.rb', line 78

def variables
  vars = config.fetch('variables', {})
  VariableInterpolation.call(vars.merge(TableSaw.configuration.variables.slice(*vars.keys)))
end