Class: Sbuilder::Ial::Model::Model

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lookupsToInit = []) ⇒ Model

Returns a new instance of Model.

Parameters:

  • lookupsToInit (:Symbol:Array) (defaults to: [])

    lookup types to inialize



14
15
16
17
18
19
# File 'lib/model/model.rb', line 14

def initialize( lookupsToInit = [] )
  @lookups = {}
  lookupsToInit.each do |type|
    initLookup( type )
  end
end

Instance Attribute Details

#lookupsObject (readonly)



26
27
28
# File 'lib/model/model.rb', line 26

def lookups
  @lookups
end

Class Method Details

.startObject



21
22
23
# File 'lib/model/model.rb', line 21

def self.start
  self.new( Sbuilder::Ial::Model::Constants::LOOKUPS_TO_INIT )
end

Instance Method Details

#[](key) ⇒ Object

has operations



30
31
32
# File 'lib/model/model.rb', line 30

def []( key )
  @lookups[key]
end

#define(type, ref, value) ⇒ Object

sets lookups[ref] = value



51
52
53
54
55
# File 'lib/model/model.rb', line 51

def define( type, ref, value )
  raise "Application error: lookups[#{type}] - not initiliazed - should have run 'initLookup( #{type} - known lookups #{lookups.keys.join(',')})'" unless lookups[type].is_a?(Hash)
  lookups[type][ref] = value
  self
end

#initLookup(type) ⇒ Object

Creates a lookup hash for ‘type’

Parameters:

  • type (:Symbol)

    of looupk to create



41
42
43
44
45
# File 'lib/model/model.rb', line 41

def initLookup( type )
  raise "Lookup already initiazed for type' #{type}'" unless lookups[type].nil?
  lookups[type] = {}
  self
end

#keysObject



34
35
36
# File 'lib/model/model.rb', line 34

def keys()
  @lookups.keys
end

#lookup(type, ref = nil) ⇒ Object



58
59
60
61
62
# File 'lib/model/model.rb', line 58

def lookup( type, ref=nil )
  raise "Should have run 'initLookup( #{type} )'" if lookups[type].nil?
  return lookups[type].keys if ref.nil?
  lookups[type][ref]
end