Class: Cranium::Transformation::Index
- Inherits:
-
Object
- Object
- Cranium::Transformation::Index
- Defined in:
- lib/cranium/transformation/index.rb
Instance Method Summary collapse
-
#initialize ⇒ Index
constructor
A new instance of Index.
- #insert(field_name, options) ⇒ Object
- #lookup(field_name, options) ⇒ Object
- #validate(options) ⇒ Object
Constructor Details
#initialize ⇒ Index
Returns a new instance of Index.
3 4 5 |
# File 'lib/cranium/transformation/index.rb', line 3 def initialize @indexes = {} end |
Instance Method Details
#insert(field_name, options) ⇒ Object
32 33 34 |
# File 'lib/cranium/transformation/index.rb', line 32 def insert(field_name, ) Cranium::DimensionManager.for([:table], [field_name]).insert(field_name, [:record]) end |
#lookup(field_name, options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cranium/transformation/index.rb', line 9 def lookup(field_name, ) validate cache = cache_for([:from_table], key_fields(), field_name) if cache.has_key? keys() cache[keys()] elsif .has_key? :if_not_found_then case [:if_not_found_then] when Proc [:if_not_found_then].call else [:if_not_found_then] end elsif .has_key? :if_not_found_then_insert cache[keys()] = Cranium::DimensionManager.for([:from_table], key_fields()).insert(field_name, default_value_record()) else :not_found end end |
#validate(options) ⇒ Object
38 39 40 |
# File 'lib/cranium/transformation/index.rb', line 38 def validate() raise ArgumentError, "Cannot specify both :if_not_found_then and :if_not_found_then_insert options" if .has_key? :if_not_found_then_insert and .has_key? :if_not_found_then end |