Class: Synthra::Mixin::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/synthra/mixin.rb

Overview

Registry for storing mixins

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



49
50
51
52
# File 'lib/synthra/mixin.rb', line 49

def initialize
  @mixins = {}
  @mutex = Mutex.new
end

Class Method Details

.allObject



44
45
46
# File 'lib/synthra/mixin.rb', line 44

def all
  instance.all
end

.clearObject



40
41
42
# File 'lib/synthra/mixin.rb', line 40

def clear
  instance.clear
end

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/synthra/mixin.rb', line 36

def exists?(name)
  instance.exists?(name)
end

.get(name) ⇒ Object



32
33
34
# File 'lib/synthra/mixin.rb', line 32

def get(name)
  instance.get(name)
end

.instanceObject



24
25
26
# File 'lib/synthra/mixin.rb', line 24

def instance
  @instance ||= new
end

.register(name, fields:, behaviors: []) ⇒ Object



28
29
30
# File 'lib/synthra/mixin.rb', line 28

def register(name, fields:, behaviors: [])
  instance.register(name, fields: fields, behaviors: behaviors)
end

Instance Method Details

#allObject

Get all mixins



94
95
96
# File 'lib/synthra/mixin.rb', line 94

def all
  @mutex.synchronize { @mixins.dup }
end

#clearObject

Clear all mixins



89
90
91
# File 'lib/synthra/mixin.rb', line 89

def clear
  @mutex.synchronize { @mixins.clear }
end

#exists?(name) ⇒ Boolean

Check if mixin exists

Parameters:

  • name (String)

    mixin name

Returns:

  • (Boolean)


84
85
86
# File 'lib/synthra/mixin.rb', line 84

def exists?(name)
  @mutex.synchronize { @mixins.key?(name.to_s) }
end

#get(name) ⇒ Hash?

Get a mixin by name

Parameters:

  • name (String)

    mixin name

Returns:

  • (Hash, nil)

    mixin definition



75
76
77
# File 'lib/synthra/mixin.rb', line 75

def get(name)
  @mutex.synchronize { @mixins[name.to_s] }
end

#register(name, fields:, behaviors: []) ⇒ Object

Register a mixin

Parameters:

  • name (String)

    mixin name

  • fields (Array<Field>)

    mixin fields

  • behaviors (Array<Hash>) (defaults to: [])

    mixin behaviors



60
61
62
63
64
65
66
67
68
# File 'lib/synthra/mixin.rb', line 60

def register(name, fields:, behaviors: [])
  @mutex.synchronize do
    @mixins[name.to_s] = {
      name: name.to_s,
      fields: fields,
      behaviors: behaviors
    }
  end
end