Class: Yoda::Store::Objects::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
Addressable, Patchable, Serializable
Defined in:
lib/yoda/store/objects/base.rb

Overview

This class is abstract.

Direct Known Subclasses

MethodObject, NamespaceObject, ValueObject

Defined Under Namespace

Classes: Connected

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

#derive, included, #to_json

Constructor Details

#initialize(path:, document: '', tag_list: [], sources: [], primary_source: nil, json_class: nil, kind: nil) ⇒ Base

Returns a new instance of Base.

Parameters:

  • path (String)
  • document (String) (defaults to: '')
  • tag_list (Array<Tag>, nil) (defaults to: [])
  • sources (Array<(String, Integer, Integer)>) (defaults to: [])
  • primary_source ((String, Integer, Integer), nil) (defaults to: nil)


84
85
86
87
88
89
90
# File 'lib/yoda/store/objects/base.rb', line 84

def initialize(path:, document: '', tag_list: [], sources: [], primary_source: nil, json_class: nil, kind: nil)
  @path = path
  @document = document
  @tag_list = tag_list
  @sources = sources
  @primary_source = primary_source
end

Instance Attribute Details

#documentString (readonly)

Returns:

  • (String)


68
69
70
# File 'lib/yoda/store/objects/base.rb', line 68

def document
  @document
end

#pathString (readonly)

Returns:

  • (String)


65
66
67
# File 'lib/yoda/store/objects/base.rb', line 65

def path
  @path
end

#primary_source(String, Integer, Integer)? (readonly)

Returns:

  • ((String, Integer, Integer), nil)


77
78
79
# File 'lib/yoda/store/objects/base.rb', line 77

def primary_source
  @primary_source
end

#sourcesArray<(String, Integer, Integer)> (readonly)

Returns:

  • (Array<(String, Integer, Integer)>)


74
75
76
# File 'lib/yoda/store/objects/base.rb', line 74

def sources
  @sources
end

#tag_listArray<Tag> (readonly)

Returns:



71
72
73
# File 'lib/yoda/store/objects/base.rb', line 71

def tag_list
  @tag_list
end

Class Method Details

.attr_namesArray<Symbol>

Returns:

  • (Array<Symbol>)


14
15
16
# File 'lib/yoda/store/objects/base.rb', line 14

def attr_names
  %i(path document tag_list sources primary_source)
end

Instance Method Details

#==(another) ⇒ Object



146
147
148
# File 'lib/yoda/store/objects/base.rb', line 146

def ==(another)
  eql?(another)
end

#addressString

Returns:

  • (String)


103
104
105
# File 'lib/yoda/store/objects/base.rb', line 103

def address
  path
end

#eql?(another) ⇒ Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/yoda/store/objects/base.rb', line 142

def eql?(another)
  another.respond_to?(:kind) && self.kind == another.kind && to_h == another.to_h
end

#hashObject



138
139
140
# File 'lib/yoda/store/objects/base.rb', line 138

def hash
  ([self.class.name] + to_h.to_a).hash
end

#kindSymbol

Returns:

  • (Symbol)


98
99
100
# File 'lib/yoda/store/objects/base.rb', line 98

def kind
  fail NotImplementedError
end

#merge(another) ⇒ self

Parameters:

  • another (self)

Returns:

  • (self)


134
135
136
# File 'lib/yoda/store/objects/base.rb', line 134

def merge(another)
  Merger.new([self, another]).merged_instance
end

#meta_class_addressString

Returns:

  • (String)


108
109
110
# File 'lib/yoda/store/objects/base.rb', line 108

def meta_class_address
  MetaClassObject.address_of(address)
end

#nameString

Returns:

  • (String)


93
94
95
# File 'lib/yoda/store/objects/base.rb', line 93

def name
  fail NotImplementedError
end

#namespace?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/yoda/store/objects/base.rb', line 150

def namespace?
  false
end

#parent_addressString

Returns:

  • (String)


113
114
115
116
117
118
# File 'lib/yoda/store/objects/base.rb', line 113

def parent_address
  @parent_address ||= begin
    sliced_address = address.slice(0, (path.rindex('::') || 0))
    sliced_address.empty? ? 'Object' : sliced_address
  end
end

#to_hHash

Returns:

  • (Hash)


121
122
123
124
125
126
127
128
129
130
# File 'lib/yoda/store/objects/base.rb', line 121

def to_h
  {
    kind: kind,
    path: path,
    document: document,
    tag_list: tag_list,
    sources: sources,
    primary_source: primary_source,
  }
end

#with_connection(**kwargs) ⇒ Connected

Returns:



155
156
157
# File 'lib/yoda/store/objects/base.rb', line 155

def with_connection(**kwargs)
  self.class.const_get(:Connected).new(self, **kwargs)
end