This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Artifact types #24
Merged
Merged
Artifact types #24
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'uri' | ||
require 'pathname' | ||
|
||
module Shanty | ||
# Public: Contain information on an artifact published by a project | ||
class Artifact | ||
attr_reader :file_extension, :plugin, :uri | ||
|
||
# Public: Initialise an artifact instance. | ||
# | ||
# file_extension - The extension of the artifact. | ||
# plugin - The plugin publishing the artifact. | ||
# uri - The URI to the object. | ||
# | ||
# Fails if the URI is not absolute or a scheme is missing. | ||
def initialize(file_extension, plugin, uri) | ||
@file_extension = file_extension | ||
@plugin = plugin | ||
@uri = uri | ||
|
||
validate_uri | ||
end | ||
|
||
# Public: Whether the underlying URI of the artifact points to a local | ||
# file path. | ||
# | ||
# Returns a Boolean representing whether the artifact is local. | ||
def local? | ||
@uri.scheme == 'file' | ||
end | ||
|
||
# Public: If the underlying artifact is stored locally, returns the path | ||
# at which the artifact can be found. | ||
# | ||
# Returns a String representing the path at which the artifact can be found. | ||
# Raises RuntimeError if the artifact is not local. | ||
def to_local_path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs for this method, will need to mention the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
return @uri.path if local? | ||
fail 'URI is not a local resource' | ||
end | ||
|
||
# Public: A simple string representation of this artifact. | ||
# | ||
# Returns a String representing the URI at which this artifact can be found. | ||
def to_s | ||
@uri.to_s | ||
end | ||
|
||
private | ||
|
||
def validate_uri | ||
fail 'Scheme not present on URI' unless @uri.absolute? | ||
fail 'URI is not absolute' if @uri.path.nil? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ def cucumber_projects | |
end | ||
end | ||
|
||
def cucumber | ||
def cucumber(_) | ||
system 'cucumber' | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ def rspec_projects | |
end | ||
end | ||
|
||
def rspec | ||
def rspec(_) | ||
system 'rspec' | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,36 @@ | ||
require 'shanty/plugin' | ||
require 'shanty/artifact' | ||
|
||
module Shanty | ||
# Public: Rubygem plugin for buildin gems. | ||
class RubygemPlugin < Plugin | ||
ARTIFACT_EXTENSION = 'gem' | ||
|
||
tags :rubygem | ||
projects '**/*.gemspec' | ||
subscribe :build, :build_gem | ||
|
||
def build_gem | ||
system 'gem build *.gemspec' | ||
def build_gem(project) | ||
gemspec_files(project).each do |file| | ||
system "gem build #{file}" | ||
end | ||
end | ||
|
||
def artifacts(project) | ||
gemspec_files(project).flat_map do |file| | ||
gemspec = Gem::Specification.load(file) | ||
Artifact.new( | ||
ARTIFACT_EXTENSION, | ||
'rubygem', | ||
URI("file://#{project.path}/#{gemspec.name}-#{gemspec.version}.#{ARTIFACT_EXTENSION}") | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def gemspec_files(project) | ||
@gemspec_files ||= project_tree.glob(File.join(project.path, '*.gemspec')) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'shanty/artifact' | ||
|
||
# All classes referenced belong to the shanty project | ||
module Shanty | ||
RSpec.describe(Artifact) do | ||
subject { described_class.new('html', 'test', uri) } | ||
let(:relative_path_artifact) { described_class.new('html', 'test', URI('file:kim/cage.html')) } | ||
let(:http_artifact) { described_class.new('html', 'test', URI('http://www.nic.com/kim/cage.html')) } | ||
let(:schemless_artifact) { described_class.new('html', 'test', URI('kim/cage.html')) } | ||
|
||
let(:uri) { URI('file:///nic/kim/cage.html') } | ||
|
||
describe('.new') do | ||
it('fails if the URI is not an absolute path') do | ||
expect { relative_path_artifact }.to raise_error('URI is not absolute') | ||
end | ||
|
||
it('fails if there is no scheme present in the URI') do | ||
expect { schemless_artifact }.to raise_error('Scheme not present on URI') | ||
end | ||
end | ||
|
||
describe('#local?') do | ||
it('returns false if the file is not a local file') do | ||
expect(http_artifact.local?).to be(false) | ||
end | ||
|
||
it('returns true if the file is a local file') do | ||
expect(subject.local?).to be(true) | ||
end | ||
end | ||
|
||
describe('#to_local_path') do | ||
it('throws an exception if the resource is not local') do | ||
allow(subject).to receive(:local?).and_return(false) | ||
expect { subject.to_local_path }.to raise_error('URI is not a local resource') | ||
end | ||
|
||
it('returns the path if the resource is local') do | ||
expect(subject.to_local_path).to eql('/nic/kim/cage.html') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will need to add docs for this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.