Class: SkadateGems::Dev::SourceController

Inherits:
Object
  • Object
show all
Defined in:
lib/skadategems/dev/source_controller.rb

Overview

Skadate software source controller

Defined Under Namespace

Classes: ParseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_dir) ⇒ SourceController

Returns a new instance of SourceController.

Parameters:

  • root_dir (String)

    source root directory



13
14
15
# File 'lib/skadategems/dev/source_controller.rb', line 13

def initialize(root_dir)
  @root = root_dir
end

Instance Attribute Details

#rootString (readonly)

Returns source root directory.

Returns:

  • (String)

    source root directory



10
11
12
# File 'lib/skadategems/dev/source_controller.rb', line 10

def root
  @root
end

Instance Method Details

#config_phpString

Returns full path to a ‘internals/config.php` file.

Returns:

  • (String)

    full path to a ‘internals/config.php` file



91
92
93
# File 'lib/skadategems/dev/source_controller.rb', line 91

def config_php
  filename ("internals/#{(version!.build < 2960 ? '$config.php' : 'config.php')}")
end

#external_cString

Returns full path to a ‘external_c/` directory.

Returns:

  • (String)

    full path to a ‘external_c/` directory



81
82
83
# File 'lib/skadategems/dev/source_controller.rb', line 81

def external_c
  filename (version!.build < 2960 ? '$external_c' : 'external_c')
end

#filename(relative_path) ⇒ String

Get full path to a file from the current source model.

Parameters:

  • relative_path (String)

    relative path to a file

Returns:

  • (String)

    absolute path to a file



20
21
22
# File 'lib/skadategems/dev/source_controller.rb', line 20

def filename(relative_path)
  File.join(@root, relative_path)
end

#header_inc_phpString

Returns full path to a ‘internals/Header.inc.php` file.

Returns:

  • (String)

    full path to a ‘internals/Header.inc.php` file



25
26
27
# File 'lib/skadategems/dev/source_controller.rb', line 25

def header_inc_php
  filename 'internals/Header.inc.php'
end

#internal_cString

Returns full path to a ‘internal_c/` directory.

Returns:

  • (String)

    full path to a ‘internal_c/` directory



76
77
78
# File 'lib/skadategems/dev/source_controller.rb', line 76

def internal_c
  filename (version!.build < 2960 ? '$internal_c' : 'internal_c')
end

#parse_version_definitionObject

Search and parse for a version definition within the ‘#header_inc_php` file.

Raises:



67
68
69
70
71
72
73
# File 'lib/skadategems/dev/source_controller.rb', line 67

def parse_version_definition
  File.open(header_inc_php) do |file|
    /define\(\s?(['"])PACKAGE_VERSION\1\s?,\s?(['"])(\d{1,2}.\d{1,2}.\d{4})\2\s?\)\s?;/.match(file.read)
  end

  $3 or raise ParseError
end

#userfilesString

Returns full path to a ‘userfiles/` directory.

Returns:

  • (String)

    full path to a ‘userfiles/` directory



86
87
88
# File 'lib/skadategems/dev/source_controller.rb', line 86

def userfiles
  filename (version!.build < 2960 ? '$userfiles' : 'userfiles')
end

#versionSoftwareVersion

Silently tries to get software version object.

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/skadategems/dev/source_controller.rb', line 31

def version
  return @version if @version

  begin
    string_def = parse_version_definition
    if SoftwareVersion::MAP.key?(string_def)
      @version = SoftwareVersion::MAP[string_def]
    else
      @version = SoftwareVersion.new(string_def)
    end
  rescue Errno::ENOENT, ParseError
    nil
  end
end

#version!SoftwareVersion

Returns software version object.

Returns:

Raises:

  • (IOError)

    if ‘internals/Header.inc.php` can not be found

  • (SoftwareVersion::IncompatibilityError)

    if detected version is not compatible with current version of ‘skadategems-dev`



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/skadategems/dev/source_controller.rb', line 50

def version!
  if @version.nil?
    string_def = parse_version_definition

    if SoftwareVersion::MAP.key?(string_def)
      @version = SoftwareVersion::MAP[string_def]
    else
      raise SoftwareVersion::CompatibilityError
    end
  end

  @version
end