Class: SkadateGems::Dev::SourceController
- Inherits:
-
Object
- Object
- SkadateGems::Dev::SourceController
- Defined in:
- lib/skadategems/dev/source_controller.rb
Overview
Skadate software source controller
Defined Under Namespace
Classes: ParseError
Instance Attribute Summary collapse
-
#root ⇒ String
readonly
Source root directory.
Instance Method Summary collapse
-
#config_php ⇒ String
Full path to a ‘internals/config.php` file.
-
#external_c ⇒ String
Full path to a ‘external_c/` directory.
-
#filename(relative_path) ⇒ String
Get full path to a file from the current source model.
-
#header_inc_php ⇒ String
Full path to a ‘internals/Header.inc.php` file.
-
#initialize(root_dir) ⇒ SourceController
constructor
A new instance of SourceController.
-
#internal_c ⇒ String
Full path to a ‘internal_c/` directory.
-
#parse_version_definition ⇒ Object
Search and parse for a version definition within the ‘#header_inc_php` file.
-
#userfiles ⇒ String
Full path to a ‘userfiles/` directory.
-
#version ⇒ SoftwareVersion
Silently tries to get software version object.
-
#version! ⇒ SoftwareVersion
Software version object.
Constructor Details
#initialize(root_dir) ⇒ SourceController
Returns a new instance of SourceController.
13 14 15 |
# File 'lib/skadategems/dev/source_controller.rb', line 13 def initialize(root_dir) @root = root_dir end |
Instance Attribute Details
#root ⇒ String (readonly)
Returns source root directory.
10 11 12 |
# File 'lib/skadategems/dev/source_controller.rb', line 10 def root @root end |
Instance Method Details
#config_php ⇒ String
Returns 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_c ⇒ String
Returns 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.
20 21 22 |
# File 'lib/skadategems/dev/source_controller.rb', line 20 def filename(relative_path) File.join(@root, relative_path) end |
#header_inc_php ⇒ String
Returns 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_c ⇒ String
Returns 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_definition ⇒ Object
Search and parse for a version definition within the ‘#header_inc_php` file.
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 |
#userfiles ⇒ String
Returns 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 |
#version ⇒ SoftwareVersion
Silently tries to get software version object.
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.
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 |