Module: Parametric::Struct
- Defined in:
- lib/parametric/struct.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #errors ⇒ Object
- #initialize(attrs = {}) ⇒ Object
- #merge(attrs = {}) ⇒ Object
-
#to_h ⇒ Object
returns a shallow copy.
- #valid? ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
5 6 7 8 |
# File 'lib/parametric/struct.rb', line 5 def self.included(base) base.send(:include, Parametric::DSL) base.extend ClassMethods end |
Instance Method Details
#==(other) ⇒ Object
28 29 30 |
# File 'lib/parametric/struct.rb', line 28 def ==(other) other.respond_to?(:to_h) && other.to_h.eql?(to_h) end |
#errors ⇒ Object
19 20 21 |
# File 'lib/parametric/struct.rb', line 19 def errors _results.errors end |
#initialize(attrs = {}) ⇒ Object
10 11 12 13 |
# File 'lib/parametric/struct.rb', line 10 def initialize(attrs = {}) @_results = self.class.schema.resolve(attrs) @_graph = self.class.build(@_results.output) end |
#merge(attrs = {}) ⇒ Object
32 33 34 |
# File 'lib/parametric/struct.rb', line 32 def merge(attrs = {}) self.class.new(to_h.merge(attrs)) end |
#to_h ⇒ Object
returns a shallow copy.
24 25 26 |
# File 'lib/parametric/struct.rb', line 24 def to_h _results.output.clone end |
#valid? ⇒ Boolean
15 16 17 |
# File 'lib/parametric/struct.rb', line 15 def valid? !_results.errors.any? end |