Class: Sinicum::Imaging::Config

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/sinicum/imaging/config.rb

Overview

Represents the configuraiton of the imaging module and its renderers

Constant Summary collapse

IMAGING_CONFIG_FILE =
"config/imaging.yml"
VERSION =

The version number of the imaging directory format. Stored in the file ‘VERSION`.

"1.0"
DEFAULT_ROOT_DIR =

Default Root directory

File.join("tmp", "imaging")
@@dir_setup =

If the directory sturcture is already set up

false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

included, #logger

Instance Attribute Details

#root_dirObject (readonly)

The root directory under which all files are stored



21
22
23
# File 'lib/sinicum/imaging/config.rb', line 21

def root_dir
  @root_dir
end

Class Method Details

.configure(configfile) ⇒ Object

Initialize and setup the configuration

‘Rails.root/config/imaging.yml` will be used.

Parameters:

  • configfile (String, nil)

    Path of the configuration file. If ‘nil`,



48
49
50
51
52
53
# File 'lib/sinicum/imaging/config.rb', line 48

def self.configure(configfile)
  config = Config.send(:new, configfile)
  @@__instance__ = config
  @@config = true
  config
end

.instanceObject

Obtain an instance of the imaging configuration.



56
57
58
59
60
# File 'lib/sinicum/imaging/config.rb', line 56

def self.instance
  @@__instance__ ||= false
  fail "Class is not yet configured" unless @@__instance__
  @@__instance__
end

.read_configurationObject



74
75
76
77
78
79
80
81
# File 'lib/sinicum/imaging/config.rb', line 74

def self.read_configuration
  config_file = File.join(Rails.root, IMAGING_CONFIG_FILE)
  if Rails.env.production?
    @@conf ||= configure(config_file)
  else
    configure(config_file)
  end
end

Instance Method Details

#converter(renderer) ⇒ Sinicum::Imaging::Converter

Returns the converter class for a given renderer

Parameters:

  • the (Symbol)

    renderer to use

Returns:



66
67
68
69
70
71
72
# File 'lib/sinicum/imaging/config.rb', line 66

def converter(renderer)
  result = nil
  renderer_config = read_config[renderer.to_s]
  result = render_type(renderer_config) if renderer_config
  result ||= DefaultConverter.new(nil)
  result
end

#file_dirString

The directory to store all rendered files in

Returns:

  • (String)


26
27
28
# File 'lib/sinicum/imaging/config.rb', line 26

def file_dir
  File.join(@root_dir, "files")
end

#tmp_dirString

The directory to store temporary files in

Returns:

  • (String)


33
34
35
# File 'lib/sinicum/imaging/config.rb', line 33

def tmp_dir
  File.join(@root_dir, "tmp")
end

#version_fileString

Path of the file that stores the version of the directory format.

Returns:

  • (String)


40
41
42
# File 'lib/sinicum/imaging/config.rb', line 40

def version_file
  File.join(@root_dir, "VERSION")
end