Class: Prick::Build
Direct Known Subclasses
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Associated database object.
-
#migration ⇒ Object
readonly
Migration object.
-
#project ⇒ Object
readonly
The associated project object.
-
#schema ⇒ Object
readonly
Schema object.
-
#version ⇒ Object
readonly
Version.
Class Method Summary collapse
-
.deref_node_file(node) ⇒ Object
Reads the name of the base release from a node (see Build#node).
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Sorting.
-
#active? ⇒ Boolean
True if the release is the active branch.
-
#base_release ⇒ Object
Base release.
- #build ⇒ Object
- #built? ⇒ Boolean
-
#checkback ⇒ Object
Doubtfull - creates strange results on Release and Prerelease branches.
- #checkout ⇒ Object
-
#create ⇒ Object
Create and checkout the branch.
-
#destroy ⇒ Object
FIXME: Kills the current branch under the feets of the application.
-
#exist? ⇒ Boolean
Return true if the build exists as a branch in git.
-
#features ⇒ Object
List of features in this build.
-
#history ⇒ Object
Return the build’s history as a hash from release to list of features.
- #include_feature(feature) ⇒ Object
-
#initialize(project, base_release, version, migration, database: nil, schema: nil) ⇒ Build
constructor
A new instance of Build.
-
#name ⇒ Object
Build name.
-
#node ⇒ Object
Path to a filesystem node that represents the build on disk.
-
#present? ⇒ Boolean
True if the release is present in this git branch.
- #rebuild ⇒ Object
- #remove_feature(feature) ⇒ Object
-
#snapshot ⇒ Object
Create a copy of the project in tmp/ and checkout the branch.
-
#to_s ⇒ Object
Use #name for String conversion.
Methods included from Ensure
#ensure_state, #ensure_state_value, #revoke_state
Constructor Details
#initialize(project, base_release, version, migration, database: nil, schema: nil) ⇒ Build
Returns a new instance of Build.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/prick/build.rb', line 62 def initialize(project, base_release, version, migration, database: nil, schema: nil) base_release.nil? || base_release.is_a?(Release) or raise Internal, "Expected a Release object, got #{base_release.class}" version.is_a?(Version) or raise Internal, "Expected a Version object, got #{version.class}" @project = project @base_release = base_release @version = version @migration = migration @schema = Schema.new(project) @database = database || Database.new("#{project.name}-#{name}", project.user) project[name] = self end |
Instance Attribute Details
#database ⇒ Object (readonly)
Associated database object
20 21 22 |
# File 'lib/prick/build.rb', line 20 def database @database end |
#migration ⇒ Object (readonly)
Migration object. Running the migration on a base release database will mutate it into the current release
27 28 29 |
# File 'lib/prick/build.rb', line 27 def migration @migration end |
#project ⇒ Object (readonly)
The associated project object
11 12 13 |
# File 'lib/prick/build.rb', line 11 def project @project end |
#schema ⇒ Object (readonly)
Schema object. Only defined when the build has been checked out
23 24 25 |
# File 'lib/prick/build.rb', line 23 def schema @schema end |
#version ⇒ Object (readonly)
Version
14 15 16 |
# File 'lib/prick/build.rb', line 14 def version @version end |
Class Method Details
.deref_node_file(node) ⇒ Object
Reads the name of the base release from a node (see Build#node)
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/prick/build.rb', line 141 def self.deref_node_file(node) if File.basename(node) == "0.0.0" nil elsif File.symlink?(node) # Releases and prereleases symlink = Command.command("readlink -v #{node}").first value = File.basename(symlink.sub(/\/$/, "")) value == "/dev/null" ? nil : value elsif File.directory?(node) # Migrations name = File.basename(node) name =~ MIGRATION_RE or raise "Illegal migration name: #{name}" $1 end end |
Instance Method Details
#<=>(other) ⇒ Object
Sorting
135 |
# File 'lib/prick/build.rb', line 135 def <=>(other) version <=> other.version end |
#active? ⇒ Boolean
True if the release is the active branch
97 |
# File 'lib/prick/build.rb', line 97 def active?() Git.current_branch == name end |
#base_release ⇒ Object
Base release. Returns nil if version is 0.0.0. Raises an exception if branch is not represented on disk and it can’t be inferred from the version (only features)
38 39 40 41 42 |
# File 'lib/prick/build.rb', line 38 def base_release() return nil if version.zero? @base_release.present? or raise Internal, "Release #{name} is not present" @base_release end |
#build ⇒ Object
111 112 113 114 |
# File 'lib/prick/build.rb', line 111 def build() active? or raise Error, "Can't build: Not active" @schema.build(@database) end |
#built? ⇒ Boolean
107 108 109 |
# File 'lib/prick/build.rb', line 107 def built?() active? && @schema.built?(@database) end |
#checkback ⇒ Object
Doubtfull - creates strange results on Release and Prerelease branches
103 104 105 |
# File 'lib/prick/build.rb', line 103 def checkback() # Doubtfull - creates strange results on Release and Prerelease branches base_release.checkout end |
#checkout ⇒ Object
99 100 101 |
# File 'lib/prick/build.rb', line 99 def checkout() Git.checkout(name) end |
#create ⇒ Object
Create and checkout the branch
79 80 81 82 83 84 |
# File 'lib/prick/build.rb', line 79 def create() !present? or raise Fail, "Build #{name} is already present on disk" !exist? or raise Fail, "Build #{name} is already present in git" Git.create_branch(name) Git.checkout_branch(name) end |
#destroy ⇒ Object
FIXME: Kills the current branch under the feets of the application. Also doesn’t update internal structures in Project
88 89 90 91 |
# File 'lib/prick/build.rb', line 88 def destroy() project.release != self or raise Error, "Can't destroy current branch - #{self.version}" Git.delete_branch(name) end |
#exist? ⇒ Boolean
Return true if the build exists as a branch in git
76 |
# File 'lib/prick/build.rb', line 76 def exist?() Git.branch?(name) end |
#features ⇒ Object
List of features in this build. This requires the build to be present on disk
45 46 47 48 |
# File 'lib/prick/build.rb', line 45 def features() present? or raise "Build #{name} is not present" version.zero? ? [] : migration.feature_versions.map { |version| project[version] } end |
#history ⇒ Object
Return the build’s history as a hash from release to list of features
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/prick/build.rb', line 51 def history() h = {} Algorithm.follow(self, :base_release).each { |release| h[release] = [] indent { release.features.each { |feature| h[release] << feature } } } h end |
#include_feature(feature) ⇒ Object
122 123 124 |
# File 'lib/prick/build.rb', line 122 def include_feature(feature) migration.include_feature(feature.migration) end |
#name ⇒ Object
Build name. Same as ‘version.to_s`
17 |
# File 'lib/prick/build.rb', line 17 def name() version.to_s end |
#node ⇒ Object
Path to a filesystem node that represents the build on disk. Used to detect if a build is present in the current release’s tree. It is possible to infer the base release from the node - either by a naming convention or by reading the file. Build::deref_node_file does that
33 |
# File 'lib/prick/build.rb', line 33 def node() raise AbstractMethod end |
#present? ⇒ Boolean
True if the release is present in this git branch
94 |
# File 'lib/prick/build.rb', line 94 def present?() File.exist?(node) end |
#rebuild ⇒ Object
116 117 118 119 120 |
# File 'lib/prick/build.rb', line 116 def rebuild() active? or raise Error, "Can't rebuild: Not active" @database.recreate build end |
#remove_feature(feature) ⇒ Object
126 127 128 |
# File 'lib/prick/build.rb', line 126 def remove_feature(feature) raise NotYet end |
#snapshot ⇒ Object
Create a copy of the project in tmp/ and checkout the branch. Used to build releases. Returns the path to the copy
132 |
# File 'lib/prick/build.rb', line 132 def snapshot() end |
#to_s ⇒ Object
Use #name for String conversion
138 |
# File 'lib/prick/build.rb', line 138 def to_s() name end |