Class: Yoda::Store::Objects::Base
Abstract
Overview
Defined Under Namespace
Classes: Connected
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#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.
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
#document ⇒ String
68
69
70
|
# File 'lib/yoda/store/objects/base.rb', line 68
def document
@document
end
|
#path ⇒ String
65
66
67
|
# File 'lib/yoda/store/objects/base.rb', line 65
def path
@path
end
|
#primary_source ⇒ (String, Integer, Integer)?
77
78
79
|
# File 'lib/yoda/store/objects/base.rb', line 77
def primary_source
@primary_source
end
|
#sources ⇒ Array<(String, Integer, Integer)>
74
75
76
|
# File 'lib/yoda/store/objects/base.rb', line 74
def sources
@sources
end
|
#tag_list ⇒ Array<Tag>
71
72
73
|
# File 'lib/yoda/store/objects/base.rb', line 71
def tag_list
@tag_list
end
|
Class Method Details
.attr_names ⇒ 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
|
#address ⇒ String
103
104
105
|
# File 'lib/yoda/store/objects/base.rb', line 103
def address
path
end
|
#eql?(another) ⇒ 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
|
#hash ⇒ Object
138
139
140
|
# File 'lib/yoda/store/objects/base.rb', line 138
def hash
([self.class.name] + to_h.to_a).hash
end
|
#kind ⇒ Symbol
98
99
100
|
# File 'lib/yoda/store/objects/base.rb', line 98
def kind
fail NotImplementedError
end
|
#merge(another) ⇒ self
134
135
136
|
# File 'lib/yoda/store/objects/base.rb', line 134
def merge(another)
Merger.new([self, another]).merged_instance
end
|
#name ⇒ String
93
94
95
|
# File 'lib/yoda/store/objects/base.rb', line 93
def name
fail NotImplementedError
end
|
#namespace? ⇒ Boolean
150
151
152
|
# File 'lib/yoda/store/objects/base.rb', line 150
def namespace?
false
end
|
#parent_address ⇒ 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_h ⇒ 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
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
|