Module: Parametric::Struct
- Defined in:
- lib/parametric/struct.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #errors ⇒ Object
- #initialize(attrs = {}) ⇒ Object
- #merge(attrs = {}) ⇒ Object
-
#to_h ⇒ Object
returns a shallow copy.
- #valid? ⇒ Boolean
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
45 46 47 |
# File 'lib/parametric/struct.rb', line 45 def ==(other) other.respond_to?(:to_h) && other.to_h.eql?(to_h) end |
#[](key) ⇒ Object
41 42 43 |
# File 'lib/parametric/struct.rb', line 41 def [](key) _results.output[key.to_sym] end |
#errors ⇒ Object
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
49 50 51 |
# File 'lib/parametric/struct.rb', line 49 def merge(attrs = {}) self.class.new(to_h.merge(attrs)) end |
#to_h ⇒ Object
returns a shallow copy.
37 38 39 |
# File 'lib/parametric/struct.rb', line 37 def to_h _results.output.clone end |
#valid? ⇒ Boolean
28 29 30 |
# File 'lib/parametric/struct.rb', line 28 def valid? !_results.errors.any? end |