Class: V::Adapters::Git::Object
- Inherits:
-
Object
- Object
- V::Adapters::Git::Object
- Defined in:
- lib/v/adapters/git/object.rb
Overview
Constant Summary collapse
- DEFN =
'def %s(*args, &block) type.%s self, *args, &block end'- INSPECT_EXCLUDES =
[:'@content', :'@name', :'@type']
- @@types =
{}
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns true if the other object has the same type and name, false otherwise.
-
#content(reload = false) ⇒ Object
Content depends on type.
-
#initialize(environment, attrs) ⇒ Object
constructor
A new instance of Object.
- #inspect ⇒ Object
-
#path(*basenames) ⇒ Object
Returns the path to the object in the current root.
- #size ⇒ Object (also: #length)
- #to_s ⇒ Object
-
#type ⇒ Object
Keep this lazy! Most objects only need a name.
Constructor Details
#initialize(environment, attrs) ⇒ Object
Returns a new instance of Object.
40 41 42 43 |
# File 'lib/v/adapters/git/object.rb', line 40 def initialize(environment, attrs) @environment = environment assign attrs end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
38 39 40 |
# File 'lib/v/adapters/git/object.rb', line 38 def environment @environment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/v/adapters/git/object.rb', line 38 def name @name end |
Class Method Details
.register_methods(*methods) ⇒ Object
30 31 32 |
# File 'lib/v/adapters/git/object.rb', line 30 def self.register_methods(*methods) methods.each { |method| class_eval DEFN.gsub('%s', method.to_s) } end |
.register_type(type) ⇒ Object
34 35 36 |
# File 'lib/v/adapters/git/object.rb', line 34 def self.register_type(type) @@types.update type end |
Instance Method Details
#==(other) ⇒ Object
Returns true if the other object has the same type and name, false otherwise.
85 86 87 |
# File 'lib/v/adapters/git/object.rb', line 85 def ==(other) type === other and name == other.name end |
#content(reload = false) ⇒ Object
Content depends on type. Since this object is typecasted on demand content can be assigned during initialize (e.g. after commit).
52 53 54 55 |
# File 'lib/v/adapters/git/object.rb', line 52 def content(reload = false) @content = type.content self if reload or not defined? @content @content end |
#inspect ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/v/adapters/git/object.rb', line 66 def inspect attrs = instance_variables.inject([]) { |m, i| if INSPECT_EXCLUDES.include? :"#{ i }" then m else m << "#{ i }=#{ instance_variable_get(:"#{ i }").inspect }" end } * ' ' type = "#{ @type }".capitalize "#<Git::#{ type }:#{ @name } #{ attrs } @content=[...]>" end |
#path(*basenames) ⇒ Object
Returns the path to the object in the current root.
79 80 81 |
# File 'lib/v/adapters/git/object.rb', line 79 def path(*basenames) type.path @parent, @basenames, *basenames end |
#size ⇒ Object Also known as: length
56 57 58 |
# File 'lib/v/adapters/git/object.rb', line 56 def size content.size end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/v/adapters/git/object.rb', line 61 def to_s type.to_s self end |
#type ⇒ Object
Keep this lazy! Most objects only need a name.
46 47 48 |
# File 'lib/v/adapters/git/object.rb', line 46 def type @@types.fetch @type end |