Module: Cube

Defined in:
lib/cube/interfaces.rb,
lib/cube/traits.rb,
lib/cube/toplevel.rb

Overview

Top level module for RubyCube

Defined Under Namespace

Modules: CubeMethods, Interface, Trait

Class Method Summary collapse

Class Method Details

.[](mod) ⇒ Object Also known as: from



10
11
12
13
14
15
16
# 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

.check_type(*_) ⇒ Object



67
68
69
70
71
# 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

.interface(&block) ⇒ Object



26
27
28
29
30
31
32
# 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) ⇒ Object



4
5
6
7
8
# 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) ⇒ Object



34
35
36
37
38
39
# 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) ⇒ Object



18
19
20
# File 'lib/cube/toplevel.rb', line 18

def self.with_super(mod)
  self[Class.new(mod)]
end