Class: Sbuilder::Ial::Model::Model
- Inherits:
-
Object
- Object
- Sbuilder::Ial::Model::Model
- Defined in:
- lib/model/model.rb
Instance Attribute Summary collapse
- #lookups ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
has operations.
-
#define(type, ref, value) ⇒ Object
sets lookups[ref] = value.
-
#initialize(lookupsToInit = []) ⇒ Model
constructor
A new instance of Model.
-
#initLookup(type) ⇒ Object
Creates a lookup hash for ‘type’.
- #keys ⇒ Object
- #lookup(type, ref = nil) ⇒ Object
Constructor Details
#initialize(lookupsToInit = []) ⇒ Model
Returns a new instance of Model.
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
#lookups ⇒ Object (readonly)
26 27 28 |
# File 'lib/model/model.rb', line 26 def lookups @lookups end |
Class Method Details
.start ⇒ Object
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’
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 |
#keys ⇒ Object
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 |