class Spark::Shard::ShardContent

Defined in:

spark/shard/shard_content.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(name : String, github : String? = nil, git : String? = nil, version : String? = nil, branch : String? = nil) #

Given some basic shard information, provides an object that can be written to shard.yml with #to_s.


[View source]

Instance Method Detail

def branch : String? #

The branch of the shard to use. Either #version or #branch may be optionally provided, but not both.

Example:

main

[View source]
def git : String? #

The git URL of the shard.

Example:

https://mycustomserver.com/stephendolan/spark

[View source]
def github : String? #

The GitHub spath of the shard.

Example:

stephendolan/spark

[View source]
def name : String #

The name of the shard


[View source]
def source #

Intelligently determine whether to use the GitHub or git source for a shard.

Outputs a shard.yml-friendly version of the source.

Example:

Spark::Shard::ShardContent.new(name: "test", github: "stephendolan/spark").source                         # => "github: stephendolan/spark"
Spark::Shard::ShardContent.new(name: "test", git: "https://custom-git.com/stephendolan/spark.git").source # => "git: https://custom-git.com/stephendolan/spark.git"

[View source]
def to_s #

Outputs a shard.yml-friendly representation of the given shard content.

Every shard should be nested under a header section, so we always indent with two spaces.

Example:

shard_content = Spark::Shard::ShardContent.new(name: "spark", github: "stephendolan/spark", version: "~> 1.0.3")
shard_content.to_s # => <<-CONTENT
  spark:
    github: stephendolan/spark
    version: ~> 1.0.3
CONTENT

[View source]
def version : String? #

The version of the shard. Either #version or #branch may be optionally provided, but not both.

Example:

~> 1.0.3

[View source]
def version_or_branch #

Intelligently determine whether to use the branch or a version string for the shard.

Outputs a shard.yml-friendly variant of the version or branch, which is always suffixed with a newline since it is the last line in a shard definition. This allows for a simpler #to_s implementation.

Example:

Spark::Shard::ShardContent.new(name: "test", github: "stephendolan/spark", version: "~> 1.0.3").version_or_branch # => "version: ~> 1.0.3\n"
Spark::Shard::ShardContent.new(name: "test", github: "stephendolan/spark", branch: "main").version_or_branch      # => "branch: main\n"

[View source]