Class: Graphlyte::Data
- Inherits:
-
Object
show all
- Defined in:
- lib/graphlyte/data.rb
Overview
Very simplistic data-class. Inheritance is not modelled.
Direct Known Subclasses
Document, Schema, Schema::Directive, Schema::Enum, Schema::Field, Schema::InputValue, Schema::Type, Schema::TypeRef, Syntax::Argument, Syntax::Field, Syntax::Fragment, Syntax::FragmentSpread, Syntax::NumericLiteral, Syntax::Operation, Syntax::Type, Syntax::Value, Syntax::VariableReference
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(**kwargs) ⇒ Data
Permissive constructor: ignores unknown attributes
23
24
25
26
27
|
# File 'lib/graphlyte/data.rb', line 23
def initialize(**kwargs)
self.class.attributes.each do |arg|
send(:"#{arg}=", kwargs[arg]) if kwargs.key?(arg)
end
end
|
Class Method Details
.attr_accessor(*names) ⇒ Object
8
9
10
11
|
# File 'lib/graphlyte/data.rb', line 8
def self.attr_accessor(*names)
super
attributes.merge(names)
end
|
.attr_reader(*names) ⇒ Object
13
14
15
16
|
# File 'lib/graphlyte/data.rb', line 13
def self.attr_reader(*names)
super
attributes.merge(names)
end
|
.attributes ⇒ Object
18
19
20
|
# File 'lib/graphlyte/data.rb', line 18
def self.attributes
@attributes ||= [].to_set
end
|
Instance Method Details
#==(other) ⇒ Object
33
34
35
|
# File 'lib/graphlyte/data.rb', line 33
def ==(other)
eql?(other)
end
|
#dup ⇒ Object
41
42
43
|
# File 'lib/graphlyte/data.rb', line 41
def dup
self.class.new(**self.class.attributes.to_h { [_1, dup_attribute(_1)] })
end
|
#eql?(other) ⇒ Boolean
29
30
31
|
# File 'lib/graphlyte/data.rb', line 29
def eql?(other)
other.is_a?(self.class) && state == other.send(:state)
end
|
#hash ⇒ Object
37
38
39
|
# File 'lib/graphlyte/data.rb', line 37
def hash
state.hash
end
|
#inspect ⇒ Object
45
46
47
|
# File 'lib/graphlyte/data.rb', line 45
def inspect
"#<#{self.class} #{self.class.attributes.map { "@#{_1}=#{send(_1).inspect}" }.join(' ')}>"
end
|