Class: Jekyll::RemoteTheme::MockGemspec
- Inherits:
-
Object
- Object
- Jekyll::RemoteTheme::MockGemspec
- 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
-
#authors ⇒ Object
Returns an array of authors from the gemspec.
-
#description ⇒ Object
Returns the description from the gemspec.
-
#initialize(theme) ⇒ MockGemspec
constructor
A new instance of MockGemspec.
-
#metadata ⇒ Object
Returns metadata hash from the gemspec Note: Metadata parsing is not currently implemented.
- #runtime_dependencies ⇒ Object
-
#summary ⇒ Object
Returns the summary from the gemspec.
-
#version ⇒ Object
Returns the version from the gemspec as a Gem::Version object Note: This extracts literal version strings like “1.2.3” from the gemspec.
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
#authors ⇒ Object
Returns an array of authors from the gemspec
35 36 37 38 39 40 41 |
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 35 def @authors ||= begin match = contents&.match(AUTHORS_REGEX) # Extract author names from the array string match ? match[1].scan(%r["']!).flatten : [] end end |
#description ⇒ Object
Returns the description from the gemspec
66 67 68 69 70 71 |
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 66 def description @description ||= begin match = contents&.match(DESCRIPTION_REGEX) match ? match[1] : nil end end |
#metadata ⇒ Object
Returns metadata hash from the gemspec Note: Metadata parsing is not currently implemented
75 76 77 |
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 75 def @metadata ||= {} end |
#runtime_dependencies ⇒ Object
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 |
#summary ⇒ Object
Returns the summary from the gemspec
58 59 60 61 62 63 |
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 58 def summary @summary ||= begin match = contents&.match(SUMMARY_REGEX) match ? match[1] : "" end end |
#version ⇒ Object
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.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jekyll-remote-theme/mock_gemspec.rb', line 46 def version @version ||= begin match = contents&.match(VERSION_REGEX) # Extract the version string and convert to Gem::Version match ? Gem::Version.new(match[1]) : Gem::Version.new(DEFAULT_VERSION) rescue ArgumentError # If the version string is invalid, return default Gem::Version.new(DEFAULT_VERSION) end end |