Module: Rails::Hyperdrive::SkillTemplate
- Defined in:
- lib/rails/hyperdrive/skill_template.rb
Overview
Renders a skill's *.md.erb sources against the app's resolved bundle. The four helpers are the only supported template API, but the binding is an ordinary object rather than a sandbox: a template runs arbitrary Ruby with the privileges of whoever triggered discovery.
Defined Under Namespace
Classes: CanonicalContext, Context
Class Method Summary collapse
-
.render(source, resolved:) ⇒ Object
Errors (ERB SyntaxError included) propagate; the caller decides how to skip and warn.
- .render_canonical(source) ⇒ Object
-
.version_matches?(requirement_str, version) ⇒ Boolean
Gem::Requirement.new does not parse a single comma-separated string, so such strings are split into separate constraints first.
Class Method Details
.render(source, resolved:) ⇒ Object
Errors (ERB SyntaxError included) propagate; the caller decides how to skip and warn.
71 72 73 |
# File 'lib/rails/hyperdrive/skill_template.rb', line 71 def render(source, resolved:) ERB.new(source, trim_mode: "-").result(Context.new(resolved).template_binding) end |
.render_canonical(source) ⇒ Object
75 76 77 |
# File 'lib/rails/hyperdrive/skill_template.rb', line 75 def render_canonical(source) ERB.new(source, trim_mode: "-").result(CanonicalContext.new.template_binding) end |
.version_matches?(requirement_str, version) ⇒ Boolean
Gem::Requirement.new does not parse a single comma-separated string, so such strings are split into separate constraints first.
81 82 83 84 85 86 |
# File 'lib/rails/hyperdrive/skill_template.rb', line 81 def version_matches?(requirement_str, version) parts = Array(requirement_str).flat_map { |s| s.is_a?(String) ? s.split(",").map(&:strip) : s } Gem::Requirement.new(*parts).satisfied_by?(Gem::Version.new(version.to_s)) rescue ArgumentError false end |