Class: AlpacaBuildTool::Nuspec

Inherits:
Object
  • Object
show all
Defined in:
lib/alpacabuildtool/entities/nuspec.rb

Overview

Nuspec creates *.nuspec file content

Nuspec.new(id: 'Cool.Package',
           version: '0.0.1',
           description: 'something',
           authors: ['Vasyl', 'Kate'],
           false).to_s
# => <?xml version="1.0"?>
#    <package>
#      <metadata>
#        <id>Cool.Package</id>
#        <version>0.0.1</version>
#        <authors>Vasyl,Kate</authors>
#        <description>something</description>
#      </metadata>
#    </package>

Constant Summary collapse

OPTIONAL =
%w(title licenseUrl projectUrl copyright iconUrl
requireLicenseAcceptance releaseNotes)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package, add_common_files = true) ⇒ Nuspec

Creates instance and generate content from package config

package

package configuration

add_common_files

flag to add files like README and CHANGELOG



30
31
32
# File 'lib/alpacabuildtool/entities/nuspec.rb', line 30

def initialize(package, add_common_files = true)
  @content = generate(package, add_common_files)
end

Class Method Details

.add_files(package, config) ⇒ Object

Adds README.txt and CHANGES.txt files

package

XmlNode where to add files entry

config

package configuration



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/alpacabuildtool/entities/nuspec.rb', line 94

def self.add_files(package, config)
  package.node 'files' do
    node 'file' do
      attribute 'src', 'README.txt'
      attribute 'target', ''
    end if config['readme']
    node 'file' do
      attribute 'src', 'CHANGES.txt'
      attribute 'target', ''
    end
  end
end

.add_mandatory_fields(metadata, config) ⇒ Object

Adds mandatory entries to nuspec like id, version, authors and description

metadata

XmlNode where to add entries

config

package configuration



71
72
73
74
75
76
# File 'lib/alpacabuildtool/entities/nuspec.rb', line 71

def self.add_mandatory_fields(, config)
  .node 'id', config['id']
  .node 'version', config['version']
  .node 'authors', config['authors'].join(',')
  .node 'description', config['description']
end

.add_metadata(package, config) ⇒ Object

Adds metadata entry to nuspec

package

XmlNode where to add metadata

config

package configuration



59
60
61
62
63
64
# File 'lib/alpacabuildtool/entities/nuspec.rb', line 59

def self.(package, config)
  package.node 'metadata' do ||
    Nuspec.add_mandatory_fields(, config)
    Nuspec.add_optional_fields(, config)
  end
end

.add_optional_fields(metadata, config) ⇒ Object

Adds optional entries to nuspec like owners, tags and so on

metadata

XmlNode where to add entries

config

package configuration



83
84
85
86
87
# File 'lib/alpacabuildtool/entities/nuspec.rb', line 83

def self.add_optional_fields(, config)
  OPTIONAL.each { |name| .node(name, config[name]) if config[name] }
  .node 'owners', config['owners'].join(',') if config['owners']
  .node 'tags', config['tags'].join(' ') if config['tags']
end

Instance Method Details

#generate(config, add_common_files) ⇒ Object

Returns Xml object representation of package nuspec

config

package configuration

add_common_files

flag to add common files or not



45
46
47
48
49
50
51
52
# File 'lib/alpacabuildtool/entities/nuspec.rb', line 45

def generate(config, add_common_files)
  Xml.new '1.0' do
    node 'package' do |package|
      Nuspec.(package, config)
      Nuspec.add_files(package, config) if add_common_files
    end
  end
end

#to_sObject

Overrides to_s method to create string content from inner Xml object



36
37
38
# File 'lib/alpacabuildtool/entities/nuspec.rb', line 36

def to_s
  @content.to_s
end