-
Notifications
You must be signed in to change notification settings - Fork 0
Artifact types #24
Artifact types #24
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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? | ||
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. Will need to add docs for this method. 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. |
||
@uri.scheme == 'file' | ||
end | ||
|
||
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 | ||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,10 @@ def projects | |
end | ||
end | ||
|
||
def artifacts(*) | ||
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. I suspect this should actually be 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. |
||
[] | ||
end | ||
|
||
def with_graph(graph) | ||
callbacks = self.class.instance_variable_get(:@with_graph_callbacks) | ||
return [] if callbacks.nil? || callbacks.empty? | ||
|
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| | ||
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. Use |
||
gemspec = Gem::Specification.load(file) | ||
Artifact.new( | ||
ARTIFACT_EXTENSION, | ||
'rubygem', | ||
URI("file://#{project.path}/#{gemspec.name}-#{gemspec.version}.#{ARTIFACT_EXTENSION}") | ||
) | ||
end | ||
end | ||
end | ||
end |
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 | ||
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. I'm going to slightly reorder and rename these describe blocks as these should actually be real method names, eg. |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,18 @@ module Shanty | |
subject.build_gem | ||
end | ||
end | ||
|
||
describe('#artifacts') do | ||
it('lists the project artifacts') do | ||
path = File.join(File.dirname(__FILE__), '..', '..', '..', '..') | ||
result = subject.artifacts(Project.new(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. You should change the: include_context('basics') above to include_context('graph') And then modify these two lines to: FileUtils.write(File.join(project_path, 'foo.gemspec'), 'gemspec contents here')
result = subject.artifacts(project_path) Adding the Reasoning here is that we've elsewhere stopped testing using example projects in Shanty itself and have moved to making a temporary folder with more testable mocks. It avoids lots of weird relative path nonsense which makes moving things around a total pain. |
||
|
||
expect(result.length).to eql(1) | ||
expect(File.dirname(result.first.to_local_path)).to eql(path) | ||
expect(result.first.file_extension).to eql('gem') | ||
expect(result.first.local?).to be true | ||
expect(result.first.uri.scheme).to eql('file') | ||
end | ||
end | ||
end | ||
end |
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.
Looks like this last bit of the documentation may not be valid still.
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.