Class: Albacore::AppSpec

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/albacore/app_spec.rb

Overview

a spec object

Defined Under Namespace

Classes: Defaults, IisSite

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #err, #error, #fatal, #info, #puts, #trace, #warn

Constructor Details

#initialize(descriptor_path, data, semver = nil) ⇒ AppSpec

Create a new app spec from yaml data; will use heuristics to let the developer avoid as much typing and definition mongering as possible; for details see the unit tests and the documentation for this class.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/albacore/app_spec.rb', line 19

def initialize descriptor_path, data, semver = nil
  raise ArgumentError, 'data is nil' unless data
  @path = descriptor_path
  @conf = YAML.load(data) || Hash.new

  project_path = resolve_project descriptor_path, @conf
  raise ArgumentError, "couldn't find project, descriptor_path: #{descriptor_path.inspect}" unless valid_path project_path

  @proj = Project.new project_path
  @semver = semver
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

Listen to all ‘getters’



223
224
225
226
227
# File 'lib/albacore/app_spec.rb', line 223

def method_missing name, *args, &block
  unless name =~ /\w=$/
    @conf.send(:'[]', *[name.to_s, args].flatten, &block)
  end
end

Instance Attribute Details

#confObject (readonly)

the loaded configuration in that appspec



76
77
78
# File 'lib/albacore/app_spec.rb', line 76

def conf
  @conf
end

#pathObject (readonly)

path of the *.appspec



33
34
35
# File 'lib/albacore/app_spec.rb', line 33

def path
  @path
end

#projObject (readonly)

the project the spec applies to



79
80
81
# File 'lib/albacore/app_spec.rb', line 79

def proj
  @proj
end

Class Method Details

.load(descriptor_path) ⇒ Object

load the App Spec from a descriptor path

Raises:

  • (ArgumentError)


177
178
179
180
181
# File 'lib/albacore/app_spec.rb', line 177

def self.load descriptor_path
  raise ArgumentError, 'missing parameter descriptor_path' unless descriptor_path
  raise ArgumentError, 'descriptor_path does not exist' unless File.exists? descriptor_path
  AppSpec.new(descriptor_path, File.read(descriptor_path))
end

Instance Method Details

#bin_folder(configuration = 'Release') ⇒ Object

gets the binary folder, first from .appspec then from proj given a configuration mode (default: Release)



134
135
136
# File 'lib/albacore/app_spec.rb', line 134

def bin_folder configuration = 'Release'
  conf['bin'] || proj.output_path(configuration)
end

#categoryObject

gets the category this package is in, both for the RPM and for puppet and for possibly assigning to a work-stealing cluster or to start the app in the correct node-cluster if you have that implemented



112
113
114
# File 'lib/albacore/app_spec.rb', line 112

def category
  conf['category'] || 'apps'
end

#conf_folderObject

gets the folder that is used to keep configuration that defaults to the current (.) directory



140
141
142
# File 'lib/albacore/app_spec.rb', line 140

def conf_folder
  conf['conf_folder'] || '.'
end

#contentsObject

gets an enumerable list of paths that are the ‘main’ contents of the package



147
148
149
# File 'lib/albacore/app_spec.rb', line 147

def contents
  conf['contents'] || []
end

#descriptionObject

the description that is used when installing and reading about the package in the package manager



100
101
102
# File 'lib/albacore/app_spec.rb', line 100

def description
  conf['description'] || proj.description
end

#dir_pathObject

gets the fully qualified path of the directory where the appspec file is



82
83
84
# File 'lib/albacore/app_spec.rb', line 82

def dir_path
  File.expand_path(File.dirname(@path))
end

#exeObject

Gets the executable name if this service has one – defaults to the assembly name of the corresponding project, plus ‘exe’, which is how the compilers name the executables.



41
42
43
# File 'lib/albacore/app_spec.rb', line 41

def exe
  conf['exe'] || "#{proj.asmname}.exe"
end

#find_first_project(descriptor_path) ⇒ Object

Given a descriptor path, tries to find the first matching project file. If you have multiple project files, the order of which Dir#glob returns values will determine which is chosen



65
66
67
68
69
70
# File 'lib/albacore/app_spec.rb', line 65

def find_first_project descriptor_path
  trace { "didn't have a valid project_path, trying to find first project at #{descriptor_path.inspect}" }
  dir = File.dirname descriptor_path
  abs_dir = File.expand_path dir
  Dir.glob(File.join(abs_dir, '*proj')).sort.first
end

#host_headerObject

Gets the host header to use for the binding in IIS - defaults to *, i.e. binding to all hosts



169
170
171
# File 'lib/albacore/app_spec.rb', line 169

def host_header
  conf['host_header'] || '*'
end

#licenseObject

gets the license that the app is licensed under



117
118
119
# File 'lib/albacore/app_spec.rb', line 117

def license
  conf['license'] || proj.license
end

#portObject

Gets the configured port to bind the site to



162
163
164
# File 'lib/albacore/app_spec.rb', line 162

def port
  conf['port'] || '80'
end

#providerObject

gets the provider to use to calculate the directory paths to construct inside the nuget

defaults to the ‘defaults’ provider which can be found in ‘albacore/app_spec/defaults.rb’



156
157
158
# File 'lib/albacore/app_spec.rb', line 156

def provider
  conf['provider'] || 'defaults'
end

#resolve_project(descriptor_path, conf) ⇒ Object

Resolves the project file given an optional descriptor path or a configuration hash or both. One of the other of the parameters need to exist, or an error will be thrown.

Parameters:

  • descriptor_path

    May be nil

  • conf (#[])

    A hash or something indexable



51
52
53
54
55
56
57
58
59
60
# File 'lib/albacore/app_spec.rb', line 51

def resolve_project descriptor_path, conf
  trace { "trying to resolve project, descriptor_path: #{descriptor_path.inspect}, conf: #{conf.inspect} [AppSpec#resolve_path]" }

  project_path = conf['project_path']
  return File.join File.dirname(descriptor_path), project_path if project_path and valid_path descriptor_path

  trace { 'didn\'t have both a project_path and a descriptor_path that was valid [AppSpec#resolve_project]' }
  return project_path if project_path
  find_first_project descriptor_path
end

#titleObject

title for puppet, title for app, title for process running on server



87
88
89
# File 'lib/albacore/app_spec.rb', line 87

def title
  title_raw.downcase
end

#title_rawObject Also known as: id

the title as-is without any downcasing



92
93
94
# File 'lib/albacore/app_spec.rb', line 92

def title_raw
  conf['title'] || proj.title
end

#to_sObject

Customizing the to_s implementation to make the spec more amenable for printing



184
185
186
# File 'lib/albacore/app_spec.rb', line 184

def to_s
  "AppSpec[#{title}], #{@conf.keys.length} keys]"
end

#uriObject

gets the uri source of the project



105
106
107
# File 'lib/albacore/app_spec.rb', line 105

def uri
  conf['uri'] || git_source
end

#versionObject

gets the version with the following priorities:

- semver version passed in c'tor
- ENV['FORMAL_VERSION']
- .appspec's version
- .xxproj's version
- semver from disk
- if all above fails; use '1.0.0'


128
129
130
# File 'lib/albacore/app_spec.rb', line 128

def version
  semver_version || ENV['FORMAL_VERSION'] || conf['version'] || proj.version || semver_disk_version || '1.0.0'
end