Class: Chrysalis::Project
Overview
Represents a software development project, typically an application or library.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#version ⇒ Object
Returns the value of attribute version.
-
#working_copy ⇒ Object
Returns the value of attribute working_copy.
Instance Method Summary collapse
-
#dependency(url, params = {}) ⇒ Object
(also: #dependency=)
Add a dependency, located at
url
, to the project. - #graph(g = GRATR::Digraph.new) ⇒ Object
- #info ⇒ Object
-
#initialize {|_self| ... } ⇒ Project
constructor
A new instance of Project.
-
#retrieve ⇒ Object
Retrieve all dependencies required by the project.
- #task(name, comment) ⇒ Object
- #task?(name) ⇒ Boolean
- #task_exec_order ⇒ Object
- #url ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/chrysalis/project.rb', line 13 def name @name end |
#version ⇒ Object
Returns the value of attribute version.
14 15 16 |
# File 'lib/chrysalis/project.rb', line 14 def version @version end |
#working_copy ⇒ Object
Returns the value of attribute working_copy.
15 16 17 |
# File 'lib/chrysalis/project.rb', line 15 def working_copy @working_copy end |
Instance Method Details
#dependency(url, params = {}) ⇒ Object Also known as: dependency=
Add a dependency, located at url
, to the project.
31 32 33 |
# File 'lib/chrysalis/project.rb', line 31 def dependency(url, params = {}) @dependencies << [url, params] end |
#graph(g = GRATR::Digraph.new) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/chrysalis/project.rb', line 88 def graph(g = GRATR::Digraph.new) @dependencies.each do |url, params| raise "Illegal declaration of dependency on self." if self.url == url # If an arc has already been connected between a project and a # dependency, a cycle has been induced. This needs to be detected to # prevent this function from looping indefinately. # # For example: # libone ---depends-on--> libtwo # libtwo ---depends-on--> libone # # Would graph as follows: # libone --> libtwo # ^ | # '-----------' # # If not prevented this will keep adding edges from libone -> libtwo -> # libone -> libtwo -> libone, and on and on and on, ad infinitum. if !g.edge?(self.url, url) g.add_edge!(self.url, url) # Build the graph recursively, by telling the dependency to construct # its portion. dep = Chrysalis::Manifest.instance[url] dep.graph(g) if !dep.nil? end end return g.add_vertex!(self.url) end |
#info ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/chrysalis/project.rb', line 74 def info n = (@name ? @name : "<Unknown Name>") v = (@version ? "(#{@version})" : "") printf "- %s %s\n", n, v puts " #{self.url}" if self.url.is_a?(String) if Rake.application..trace @tasks.each do |name, comment| printf " %-18s # %s\n", name, comment end end end |
#retrieve ⇒ Object
Retrieve all dependencies required by the project.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/chrysalis/project.rb', line 48 def retrieve # A project can be declared as a dependency multiple times, which is a # common occurance for shared libraries. After the initial retrieval, the # retrieved flag is set. Subsequent retrievals are unnessesary. return if @retrieved @retrieved = true FileUtils.mkdir_p(Chrysalis..prefix) # Retrieve each direct dependency from its repository, and load it into # the manifest. @dependencies.each do |url, params| # If the URL of the project is already in the manifest, it has already # been loaded. if !Chrysalis::Manifest.instance[url] working_copy = Repository.retrieve(url, Chrysalis..prefix, params) Chrysalis::Loader.instance.load(url, working_copy) end end # Transitively retrieve dependencies. @dependencies.each do |url, params| Chrysalis::Manifest.instance[url].retrieve end end |
#task(name, comment) ⇒ Object
37 38 39 40 41 |
# File 'lib/chrysalis/project.rb', line 37 def task(name, comment) desc = (@tasks.has_key?(name) ? @tasks[name] : '') desc.concat_sep(comment, " / ") @tasks[name] = desc end |
#task?(name) ⇒ Boolean
43 44 45 |
# File 'lib/chrysalis/project.rb', line 43 def task?(name) @tasks.has_key? name end |
#task_exec_order ⇒ Object
120 121 122 123 124 125 |
# File 'lib/chrysalis/project.rb', line 120 def task_exec_order g = graph raise "Cyclic dependency detected." if g.cyclic? g.topsort.reverse end |