module Opto::Model

Constants

VERSION

Public Class Methods

included(where) click to toggle source
# File lib/opto/model.rb, line 10
def self.included(where)
  where.send :prepend, Initializer
  where.send :prepend, AttributeDeclaration
  where.send :prepend, Association
  where.send :prepend, Association::HasOne::Declaration
  where.send :prepend, Association::HasMany::Declaration
end

Public Instance Methods

errors(children = true) click to toggle source
# File lib/opto/model.rb, line 30
def errors(children = true)
  if children
    result = collection.errors
    self.class.relations.each do |relation|
      result.merge!(self.send(relation).errors)
    end
    result
  else
    collection.errors
  end
end
inspect() click to toggle source
Calls superclass method
# File lib/opto/model.rb, line 18
def inspect
  super.gsub(/\>\z/, " " + collection.members.map {|n, m| "#{m.handler.type}:#{n}: #{m.value.inspect}"}.join(', ') + ">")
end
to_h(children = true) click to toggle source
# File lib/opto/model.rb, line 42
def to_h(children = true)
  if children
    result = to_h(false)
    self.class.relations.each do |r|
      result.merge!(self.send(r).to_h)
    end
    result
  else
    collection.to_h(values_only: true)
  end
end
valid?(children = true) click to toggle source
# File lib/opto/model.rb, line 22
def valid?(children = true)
  if children
    ([collection] + self.class.relations.map { |r| self.send(r) }).all?(&:valid?)
  else
    collection.valid?
  end
end