Class: EnumerizeSchema::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_configHash (readonly)

Returns the default config.

Returns:

  • (Hash)

    the default config



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

def default_config
  return @default_config if @default_config

  config = {}

  if defined?(Rails)
    config[:schema_file] = Rails.root.join("config", "enumerize.yml")
  else
    root_path = Pathname.new(defined?(Bundler) ? Bundler.root : Dir.pwd)

    config[:schema_file] = root_path.join("enumerize.yml")
  end

  @default_config = config.freeze
end

Instance Method Details

#schema_filePathname

Returns the path to the schema file containing all the enum values.

Returns:

  • (Pathname)

    the path to the schema file containing all the enum values



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

def schema_file
  @schema_file ||= default_config[:schema_file]
end

#schema_file=(value) ⇒ Pathname

Returns the path to the schema file containing all the enum values.

Parameters:

  • value (String, File, Pathname)

    the path to the schema file containing all the enum values

Returns:

  • (Pathname)

    the path to the schema file containing all the enum values

Raises:



35
36
37
38
39
40
41
42
43
# File 'lib/enumerize_schema/configuration.rb', line 35

def schema_file=(value)
  if !File.file?(value)
    raise SchemaFileNotFoundError.new(schema_file: value)
  elsif !File.readable?(value)
    raise SchemaFileNotReadableError.new(schema_file: value)
  else
    @schema_file = Pathname.new(value)
  end
end