Module: Paradocs::Struct

Defined in:
lib/paradocs/struct.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



16
17
18
19
# File 'lib/paradocs/struct.rb', line 16

def self.included(base)
  base.send(:include, Paradocs::DSL)
  base.extend ClassMethods
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/paradocs/struct.rb', line 39

def ==(other)
  other.respond_to?(:to_h) && other.to_h.eql?(to_h)
end

#errorsObject



30
31
32
# File 'lib/paradocs/struct.rb', line 30

def errors
  _results.errors
end

#initialize(attrs = {}, environment = {}) ⇒ Object



21
22
23
24
# File 'lib/paradocs/struct.rb', line 21

def initialize(attrs = {}, environment = {})
  @_results = self.class.schema.resolve(attrs, environment)
  @_graph = self.class.build(@_results.output)
end

#merge(attrs = {}) ⇒ Object



43
44
45
# File 'lib/paradocs/struct.rb', line 43

def merge(attrs = {})
  self.class.new(to_h.merge(attrs))
end

#to_hObject

 returns a shallow copy.



35
36
37
# File 'lib/paradocs/struct.rb', line 35

def to_h
  _results.output.clone
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/paradocs/struct.rb', line 26

def valid?
  !_results.errors.any?
end