module Cube

Top level module for RubyCube

Public Class Methods

[](mod) click to toggle source
# File lib/cube/toplevel.rb, line 10
def self.[](mod)
  return mod if mod.is_a?(CubeMethods)
  unless mod.is_a?(Class)
    raise ArgumentError, "Only classes can be be converted to Cube classes"
  end
  Class.new(mod).extend(CubeMethods)
end
Also aliased as: from
check_type(t, v) click to toggle source
# File lib/cube/toplevel.rb, line 67
def self.check_type(t, v)
  return t[v] if t.is_a? Dry::Types::Type
  raise Cube::Interface::TypeMismatchError, "#{v.inspect} is not type #{t}" unless v.is_a? t
  v
end
from(mod)
Alias for: []
interface(&block) click to toggle source
# File lib/cube/toplevel.rb, line 26
def self.interface(&block)
  mod = Module.new
  mod.extend(Cube::Interface)
  mod.instance_variable_set('@ids', {})
  mod.instance_eval(&block)
  mod
end
mark_interface!(cls, iface) click to toggle source
# File lib/cube/toplevel.rb, line 4
def self.mark_interface!(cls, iface)
  Cube[cls].as_interface(iface, runtime_checks: false)
  cl_iface = iface.impotent
  cls.include(cl_iface)
end
trait(&blk) click to toggle source
# File lib/cube/toplevel.rb, line 34
def self.trait(&blk)
  m = Module.new
  m.extend(Cube::Trait)
  m.module_exec(&blk) if block_given?
  m
end
with_super(mod) click to toggle source
# File lib/cube/toplevel.rb, line 18
def self.with_super(mod)
  self[Class.new(mod)]
end