Module: Parametric::Struct

Defined in:
lib/parametric/struct.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



18
19
20
21
# File 'lib/parametric/struct.rb', line 18

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

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/parametric/struct.rb', line 41

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

#errorsObject



32
33
34
# File 'lib/parametric/struct.rb', line 32

def errors
  _results.errors
end

#initialize(attrs = {}) ⇒ Object



23
24
25
26
# File 'lib/parametric/struct.rb', line 23

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

#merge(attrs = {}) ⇒ Object



45
46
47
# File 'lib/parametric/struct.rb', line 45

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

#to_hObject

 returns a shallow copy.



37
38
39
# File 'lib/parametric/struct.rb', line 37

def to_h
  _results.output.clone
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/parametric/struct.rb', line 28

def valid?
  !_results.errors.any?
end