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

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 (TagList, nil) (defaults to: [])
  • sources (Array<(String, Integer, Integer)>) (defaults to: [])
  • primary_source ((String, Integer, Integer), nil) (defaults to: nil)


37
38
39
40
41
42
43
# File 'lib/yoda/store/objects/base.rb', line 37

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)


21
22
23
# File 'lib/yoda/store/objects/base.rb', line 21

def document
  @document
end

#pathString (readonly)

Returns:

  • (String)


18
19
20
# File 'lib/yoda/store/objects/base.rb', line 18

def path
  @path
end

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

Returns:

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


30
31
32
# File 'lib/yoda/store/objects/base.rb', line 30

def primary_source
  @primary_source
end

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

Returns:

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


27
28
29
# File 'lib/yoda/store/objects/base.rb', line 27

def sources
  @sources
end

#tag_listArray<Tag> (readonly)

Returns:



24
25
26
# File 'lib/yoda/store/objects/base.rb', line 24

def tag_list
  @tag_list
end

Class Method Details

.attr_namesArray<Symbol>

Returns:

  • (Array<Symbol>)


12
13
14
# File 'lib/yoda/store/objects/base.rb', line 12

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

Instance Method Details

#==(another) ⇒ Object



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

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

#addressString

Returns:

  • (String)


56
57
58
# File 'lib/yoda/store/objects/base.rb', line 56

def address
  path
end

#eql?(another) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/yoda/store/objects/base.rb', line 82

def eql?(another)
  self.class == another.class && to_h == another.to_h
end

#hashObject



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

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

#kindSymbol

Returns:

  • (Symbol)


51
52
53
# File 'lib/yoda/store/objects/base.rb', line 51

def kind
  fail NotImplementedError
end

#merge(another) ⇒ self

Parameters:

  • another (self)

Returns:

  • (self)


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

def merge(another)
  self.class.new(merge_attributes(another))
end

#nameString

Returns:

  • (String)


46
47
48
# File 'lib/yoda/store/objects/base.rb', line 46

def name
  fail NotImplementedError
end

#to_hHash

Returns:

  • (Hash)


61
62
63
64
65
66
67
68
69
70
# File 'lib/yoda/store/objects/base.rb', line 61

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