Class: Scrooge::Optimizations::Columns::ScroogedAttributes
- Inherits:
-
Hash
- Object
- Hash
- Scrooge::Optimizations::Columns::ScroogedAttributes
- Defined in:
- lib/optimizations/columns/attributes_proxy.rb
Instance Attribute Summary collapse
-
#callsite_signature ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access.
-
#fully_fetched ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access.
-
#klass ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access.
-
#scrooge_columns ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access.
-
#updateable_result_set ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](attr_name) ⇒ Object
Lazily augment and load missing attributes.
- #[]=(attr_name, value) ⇒ Object (also: #store)
- #delete(attr_name) ⇒ Object
- #dup ⇒ Object
- #fetch(*args, &block) ⇒ Object
- #fetch_remaining ⇒ Object
-
#has_key?(attr_name) ⇒ Boolean
(also: #include?, #key?, #member?)
Let #has_key? consider defined columns.
-
#keys ⇒ Object
Delegate Hash keys to all defined columns.
- #to_a ⇒ Object
- #to_hash ⇒ Object
- #update(hash) ⇒ Object (also: #merge!)
Instance Attribute Details
#callsite_signature ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access
34 35 36 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 34 def callsite_signature @callsite_signature end |
#fully_fetched ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access
34 35 36 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 34 def fully_fetched @fully_fetched end |
#klass ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access
34 35 36 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 34 def klass @klass end |
#scrooge_columns ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access
34 35 36 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 34 def scrooge_columns @scrooge_columns end |
#updateable_result_set ⇒ Object
Hash container for attributes with scrooge monitoring of attribute access
34 35 36 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 34 def updateable_result_set @updateable_result_set end |
Class Method Details
.setup(record, scrooge_columns, klass, callsite_signature, updateable_result_set) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 36 def self.setup(record, scrooge_columns, klass, callsite_signature, updateable_result_set) hash = new.replace(record) hash.scrooge_columns = scrooge_columns.dup hash.fully_fetched = false hash.klass = klass hash.callsite_signature = callsite_signature hash.updateable_result_set = updateable_result_set hash end |
Instance Method Details
#[](attr_name) ⇒ Object
Lazily augment and load missing attributes
64 65 66 67 68 69 70 71 72 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 64 def [](attr_name) attr_s = attr_name.to_s if interesting_for_scrooge?( attr_s ) augment_callsite!( attr_s ) fetch_remaining @scrooge_columns << attr_s end super end |
#[]=(attr_name, value) ⇒ Object Also known as: store
79 80 81 82 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 79 def []=(attr_name, value) @scrooge_columns << attr_name.to_s super end |
#delete(attr_name) ⇒ Object
100 101 102 103 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 100 def delete(attr_name) self[attr_name] super end |
#dup ⇒ Object
86 87 88 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 86 def dup super.dup_self end |
#fetch(*args, &block) ⇒ Object
74 75 76 77 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 74 def fetch(*args, &block) self[args[0]] super end |
#fetch_remaining ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 112 def fetch_remaining unless @fully_fetched columns_to_fetch = @klass.column_names - @scrooge_columns.to_a unless columns_to_fetch.empty? fetch_remaining!( columns_to_fetch ) end @fully_fetched = true end end |
#has_key?(attr_name) ⇒ Boolean Also known as: include?, key?, member?
Let #has_key? consider defined columns
54 55 56 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 54 def has_key?(attr_name) keys.include?(attr_name.to_s) end |
#keys ⇒ Object
Delegate Hash keys to all defined columns
48 49 50 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 48 def keys @klass.column_names end |
#to_a ⇒ Object
95 96 97 98 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 95 def to_a fetch_remaining super end |
#to_hash ⇒ Object
90 91 92 93 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 90 def to_hash fetch_remaining super end |
#update(hash) ⇒ Object Also known as: merge!
105 106 107 108 |
# File 'lib/optimizations/columns/attributes_proxy.rb', line 105 def update(hash) @fully_fetched = true super(hash.to_hash) end |