Skip to content

Commit

Permalink
add license_url and notes fields
Browse files Browse the repository at this point in the history
  • Loading branch information
David Goudreau & Kurtis Seebaldt committed Mar 25, 2011
1 parent 4cdcab1 commit cfa7268
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
18 changes: 8 additions & 10 deletions lib/license_finder/dependency.rb
@@ -1,30 +1,28 @@
module LicenseFinder
class Dependency

attr_reader :name, :version, :license, :approved

def self.from_yaml(yml)
attrs = YAML.load(yml)
new(attrs['name'], attrs['version'], attrs['license'], attrs['approved'])
end
attr_reader :name, :version, :license, :approved, :license_url, :notes

def self.from_hash(attrs)
new(attrs['name'], attrs['version'], attrs['license'], attrs['approved'])
new(attrs['name'], attrs['version'], attrs['license'], attrs['approved'], attrs['license_url'], attrs['notes'])
end

def initialize(name, version, license, approved)
def initialize(name, version, license, approved, license_url = '', notes = '')
@name = name
@version = version
@license = license
@approved = approved
@license_url = license_url
@notes = notes
end

def to_yaml_entry
"- name: \"#{name}\"\n version: \"#{version}\"\n license: \"#{license}\"\n approved: #{approved}\n"
"- name: \"#{name}\"\n version: \"#{version}\"\n license: \"#{license}\"\n approved: #{approved}\n license_url: \"#{license_url}\"\n notes: \"#{notes}\"\n"
end

def to_s
"#{name} #{version}, #{license}"
url = ", #{license_url}" if license_url != ''
"#{name} #{version}, #{license}#{url}"
end

end
Expand Down
7 changes: 3 additions & 4 deletions spec/dependency_list_spec.rb
Expand Up @@ -59,7 +59,6 @@ def full_gem_path
let(:dep) { subject.dependencies.first }
it { dep.name.should == 'gem1' }
it { dep.version.should == '1.2.3' }
it { dep.to_yaml_entry.should == "- name: \"gem1\"\n version: \"1.2.3\"\n license: \"MIT\"\n approved: false\n" }
end

describe "second" do
Expand All @@ -77,7 +76,7 @@ def full_gem_path
LicenseFinder::Dependency.new('a_gem', '1.2.3', 'MIT', false)
])

list.to_yaml.should == "--- \n- name: \"a_gem\"\n version: \"1.2.3\"\n license: \"MIT\"\n approved: false\n- name: \"b_gem\"\n version: \"0.4.2\"\n license: \"MIT\"\n approved: false\n"
list.to_yaml.should == "--- \n- name: \"a_gem\"\n version: \"1.2.3\"\n license: \"MIT\"\n approved: false\n license_url: \"\"\n notes: \"\"\n- name: \"b_gem\"\n version: \"0.4.2\"\n license: \"MIT\"\n approved: false\n license_url: \"\"\n notes: \"\"\n"
end
end

Expand Down Expand Up @@ -165,11 +164,11 @@ def full_gem_path
describe "#to_s" do
it "should return a human readable list of dependencies" do
gem1 = LicenseFinder::Dependency.new('b_gem', '1.2.3', 'MIT', true)
gem2 = LicenseFinder::Dependency.new('a_gem', '0.9', 'other', false)
gem2 = LicenseFinder::Dependency.new('a_gem', '0.9', 'other', false, 'http://foo.com/LICENSE')

list = LicenseFinder::DependencyList.new([gem1, gem2])

list.to_s.should == "a_gem 0.9, other\nb_gem 1.2.3, MIT"
list.to_s.should == "a_gem 0.9, other, http://foo.com/LICENSE\nb_gem 1.2.3, MIT"
end
end

Expand Down
8 changes: 6 additions & 2 deletions spec/dependency_spec.rb
Expand Up @@ -29,14 +29,18 @@ def full_gem_path


describe 'from hash' do
subject { LicenseFinder::Dependency.from_hash({'name' => "spec_name", 'version' => "2.1.3", 'license' => "MIT", 'approved' => false}) }
subject { LicenseFinder::Dependency.from_hash({'name' => "spec_name", 'version' => "2.1.3", 'license' => "MIT", 'approved' => false,
'license_url' => 'http://www.apache.org/licenses/LICENSE-2.0.html', 'notes' => 'some notes'}) }

its(:name) { should == 'spec_name' }
its(:version) { should == '2.1.3' }
its(:license) { should == 'MIT' }
its(:approved) { should == false }
its(:license_url) { should == "http://www.apache.org/licenses/LICENSE-2.0.html" }
its(:notes) { should == "some notes" }

its(:to_yaml_entry) {should == "- name: \"spec_name\"\n version: \"2.1.3\"\n license: \"MIT\"\n approved: false\n license_url: \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n notes: \"some notes\"\n"}

its(:to_yaml_entry) {should == "- name: \"spec_name\"\n version: \"2.1.3\"\n license: \"MIT\"\n approved: false\n" }

end

Expand Down
12 changes: 6 additions & 6 deletions spec/gem_spec_details_spec.rb
Expand Up @@ -72,8 +72,8 @@ def full_gem_path
its(:version) { should == '2.1.3' }
its(:license) { should == 'MIT' }
its(:approved) { should == true }

its(:to_yaml_entry) { should == "- name: \"spec_name\"\n version: \"2.1.3\"\n license: \"MIT\"\n approved: true\n" }
its(:license_url) { should == '' }
its(:notes) { should == '' }
end

describe 'with Apache License' do
Expand All @@ -85,8 +85,8 @@ def full_gem_path
its(:version) { should == '2.1.3' }
its(:license) { should == 'Apache 2.0' }
its(:approved) { should == true }

its(:to_yaml_entry) { should == "- name: \"spec_name\"\n version: \"2.1.3\"\n license: \"Apache 2.0\"\n approved: true\n" }
its(:license_url) { should == '' }
its(:notes) { should == '' }
end


Expand All @@ -97,8 +97,8 @@ def full_gem_path
its(:version) { should == '2.1.3' }
its(:license) { should == 'other' }
its(:approved) { should == false }

its(:to_yaml_entry) { should == "- name: \"spec_name\"\n version: \"2.1.3\"\n license: \"other\"\n approved: false\n" }
its(:license_url) { should == '' }
its(:notes) { should == '' }
end

end
Expand Down

0 comments on commit cfa7268

Please sign in to comment.