Class: Jekyll::RemoteTheme::MockGemspec

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jekyll-remote-theme/mock_gemspec.rb

Overview

Jekyll::Theme expects the theme’s gemspec to tell it things like the path to the theme and runtime dependencies. MockGemspec serves as a stand in, since remote themes don’t need Gemspecs

Constant Summary collapse

DEPENDENCY_PREFIX =
%r!^\s*[a-z]+\.add_(?:runtime_)?dependency!.freeze
DEPENDENCY_REGEX =
%r!#{DEPENDENCY_PREFIX}\(?\s*["']([a-z_-]+)["']!.freeze
AUTHORS_REGEX =

Regex patterns for extracting gemspec metadata

%r!^\s*[a-z_]+\.authors\s*=\s*\[(.*?)\]!m.freeze
VERSION_REGEX =
%r!^\s*[a-z_]+\.version\s*=\s*["']([^"']+)["']!.freeze
SUMMARY_REGEX =
%r!^\s*[a-z_]+\.summary\s*=\s*["'](.*?)["']!.freeze
DESCRIPTION_REGEX =
%r!^\s*[a-z_]+\.description\s*=\s*["'](.*?)["']!.freeze
DEFAULT_VERSION =

Default version when gemspec is missing or version cannot be determined

"0.0.0"

Instance Method Summary collapse

Constructor Details

#initialize(theme) ⇒ MockGemspec

Returns a new instance of MockGemspec.



24
25
26
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 24

def initialize(theme)
  @theme = theme
end

Instance Method Details

#authorsObject

Returns an array of authors from the gemspec



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 35

def authors
  @authors ||= begin
    return [] unless contents

    match = contents.match(AUTHORS_REGEX)
    return [] unless match

    # Extract author names from the array string
    match[1].scan(%r!["']([^"']+)["']!).flatten
  end
end

#descriptionObject

Returns the description from the gemspec



76
77
78
79
80
81
82
83
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 76

def description
  @description ||= begin
    return nil unless contents

    match = contents.match(DESCRIPTION_REGEX)
    match ? match[1] : nil
  end
end

#metadataObject

Returns metadata hash from the gemspec Note: Metadata parsing is not currently implemented



87
88
89
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 87

def 
  @metadata ||= {}
end

#runtime_dependenciesObject



28
29
30
31
32
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 28

def runtime_dependencies
  @runtime_dependencies ||= dependency_names.map do |name|
    Gem::Dependency.new(name)
  end
end

#summaryObject

Returns the summary from the gemspec



66
67
68
69
70
71
72
73
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 66

def summary
  @summary ||= begin
    return "" unless contents

    match = contents.match(SUMMARY_REGEX)
    match ? match[1] : ""
  end
end

#versionObject

Returns the version from the gemspec as a Gem::Version object Note: This extracts literal version strings like “1.2.3” from the gemspec. It cannot evaluate version constants like MyGem::VERSION.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 50

def version
  @version ||= begin
                 return Gem::Version.new(DEFAULT_VERSION) unless contents

                 match = contents.match(VERSION_REGEX)
                 return Gem::Version.new(DEFAULT_VERSION) unless match

                 # Extract the version string and convert to Gem::Version
                 Gem::Version.new(match[1])
               rescue ArgumentError
                 # If the version string is invalid, return default
                 Gem::Version.new(DEFAULT_VERSION)
               end
end