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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add artifact class - modify rubygem plugin to publish artifacts for each project
- Loading branch information
janstenpickle
committed
Sep 25, 2015
1 parent
654addb
commit 24d5394
Showing
7 changed files
with
128 additions
and
12 deletions.
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,44 @@ | ||
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 | ||
# the mime type is not valid | ||
def initialize(file_extension, plugin, uri) | ||
@file_extension = file_extension | ||
@plugin = plugin | ||
@uri = uri | ||
validate_uri | ||
end | ||
|
||
def local? | ||
@uri.scheme == 'file' | ||
end | ||
|
||
def to_local_path | ||
return @uri.path if local? | ||
fail 'URI is not a local resource' | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
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' | ||
end | ||
|
||
def artifacts(project) | ||
Dir[File.join(project.path, '*.gemspec')].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 | ||
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,40 @@ | ||
require 'shanty/artifact' | ||
|
||
# All classes referenced belong to the shanty project | ||
module Shanty | ||
RSpec.describe(Artifact) do | ||
subject { Artifact.new('html', 'test', uri) } | ||
|
||
describe('#localfile') do | ||
let(:uri) { URI('file:///nic/kim/cage.html') } | ||
|
||
it('works with a local file') do | ||
expect(subject.local?).to be(true) | ||
expect(subject.to_local_path).to eql('/nic/kim/cage.html') | ||
end | ||
end | ||
|
||
describe('#noscheme') do | ||
let(:uri) { URI('kim/cage.html') } | ||
it('fails if there is no scheme present in the URI') do | ||
expect { subject }.to raise_error('Scheme not present on URI') | ||
end | ||
end | ||
|
||
describe('#notabsolute') do | ||
let(:uri) { URI('file:kim/cage.html') } | ||
it('fails if the URI is not an absolute path') do | ||
expect { subject }.to raise_error('URI is not absolute') | ||
end | ||
end | ||
|
||
describe('#remotefile') do | ||
let(:uri) { URI('http://www.nic.com/kim/cage.html') } | ||
|
||
it('fails when converting to a local path if the resource is not local') do | ||
expect(subject.local?).to be(false) | ||
expect { subject.to_local_path }.to raise_error('URI is not a local resource') | ||
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