Class: Chrysalis::WorkingCopy
Overview
Represents a working copy that has been retrieved from a repository.
This class implements support for a file system-based working copy stored in a directory.
Subclasses can provide implementation for working copies with additional functionality, such as those retrieved from a version control system.
Direct Known Subclasses
Constant Summary collapse
- @@working_copies =
[self]
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.create(params) ⇒ Object
Returns a WorkingCopy constructed with
params
. -
.inherited(working_copies) ⇒ Object
:nodoc:.
- .type ⇒ Object
Instance Method Summary collapse
-
#exist? ⇒ Boolean
Returns
true
if the working copy exists on disk. -
#initialize(params = {}) ⇒ WorkingCopy
constructor
A new instance of WorkingCopy.
-
#to_hash ⇒ Object
Returns a hash which will be serialized to the cache.
Constructor Details
#initialize(params = {}) ⇒ WorkingCopy
Returns a new instance of WorkingCopy.
113 114 115 116 |
# File 'lib/chrysalis/repository.rb', line 113 def initialize(params = {}) @url = params[:url] @path = params[:path] end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
107 108 109 |
# File 'lib/chrysalis/repository.rb', line 107 def path @path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
106 107 108 |
# File 'lib/chrysalis/repository.rb', line 106 def url @url end |
Class Method Details
.create(params) ⇒ Object
Returns a WorkingCopy constructed with params
.
Using the factory design pattern, this method instantiates a new instance of WorkingCopy based on the key :type
in the params
hash.
If :type
is not supported, nil
is returned.
This method is intended to be used for the purpose of instantiating a working copies directly from the cache, to obviate the need for retrieval when the working copy already exists on the system.
95 96 97 98 99 100 101 102 103 |
# File 'lib/chrysalis/repository.rb', line 95 def self.create(params) return nil if params.nil? type = params[:type] @@working_copies.each do |working_copy| return working_copy.new(params) if working_copy.type == type end nil end |
.inherited(working_copies) ⇒ Object
:nodoc:
81 82 83 |
# File 'lib/chrysalis/repository.rb', line 81 def self.inherited(working_copies) # :nodoc: @@working_copies << working_copies end |
.type ⇒ Object
109 110 111 |
# File 'lib/chrysalis/repository.rb', line 109 def self.type :directory end |
Instance Method Details
#exist? ⇒ Boolean
Returns true
if the working copy exists on disk. Otherwise, returns false
.
Typically, if the working copy no longer exits on disk, it has been explicitly removed by a developer.
123 124 125 |
# File 'lib/chrysalis/repository.rb', line 123 def exist? Pathname.new(@path).exist? end |
#to_hash ⇒ Object
Returns a hash which will be serialized to the cache.
At a minimum, a :type
key must be present in the hash. This key is used when loading the cache, to instantiate working copies that have previously been retrieved.
Subclasses can add any additional keys and values to the hash, and utilize them for purposes of deserialization.
135 136 137 138 139 |
# File 'lib/chrysalis/repository.rb', line 135 def to_hash { :type => self.class.type, :url => @url, :path => @path } end |