Class: Spectifly::Sequel::Configuration

Inherits:
Configuration
  • Object
show all
Defined in:
lib/spectifly/sequel/configuration.rb

Constant Summary collapse

VALID_CONFIG_KEYS =
[:sequel_migration_path, :sequel_migration_version_type]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Configuration

Returns a new instance of Configuration.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/spectifly/sequel/configuration.rb', line 8

def initialize(config)
  if config.is_a? String
    config = YAML.load_file(config)
  end

  new_config = {}
  config.each { |k, v| new_config[k.to_s] = v }

  begin
    super new_config
    @migration_path = new_config.fetch('sequel_migration_path')
    @migration_version_type = get_version_type new_config['sequel_migration_version_type']
  rescue KeyError => e
    raise "Spectify::Sequel is not configured properly. \"#{e.message.sub(/"$/, '').sub(/^.*"/, '')}\" must be set via YAML or a hash."
  end
end

Instance Attribute Details

#migration_pathObject

Returns the value of attribute migration_path.



6
7
8
# File 'lib/spectifly/sequel/configuration.rb', line 6

def migration_path
  @migration_path
end

#migration_version_typeObject

Returns the value of attribute migration_version_type.



6
7
8
# File 'lib/spectifly/sequel/configuration.rb', line 6

def migration_version_type
  @migration_version_type
end

Instance Method Details

#get_version_type(type) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/spectifly/sequel/configuration.rb', line 25

def get_version_type type
  if %w(Timestamp Integer).include? type.to_s
    type
  else
    'Timestamp'
  end
end