Class: Datasource::Attributes::Loader
- Inherits:
-
Object
- Object
- Datasource::Attributes::Loader
- Defined in:
- lib/datasource/attributes/loader.rb
Class Attribute Summary collapse
-
._load_proc ⇒ Object
Returns the value of attribute _load_proc.
-
._options ⇒ Object
Returns the value of attribute _options.
Class Method Summary collapse
- .default_value ⇒ Object
- .inherited(base) ⇒ Object
- .load(*args, &block) ⇒ Object
- .options(hash) ⇒ Object
Class Attribute Details
._load_proc ⇒ Object
Returns the value of attribute _load_proc.
6 7 8 |
# File 'lib/datasource/attributes/loader.rb', line 6 def _load_proc @_load_proc end |
._options ⇒ Object
Returns the value of attribute _options.
5 6 7 |
# File 'lib/datasource/attributes/loader.rb', line 5 def @_options end |
Class Method Details
.default_value ⇒ Object
16 17 18 |
# File 'lib/datasource/attributes/loader.rb', line 16 def default_value self.[:default] end |
.inherited(base) ⇒ Object
8 9 10 |
# File 'lib/datasource/attributes/loader.rb', line 8 def inherited(base) base. = ( || {}).dup end |
.load(*args, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/datasource/attributes/loader.rb', line 20 def load(*args, &block) args = args.slice(0, _load_proc.arity) if _load_proc.arity >= 0 results = _load_proc.call(*args, &block) if [:group_by] results = Array(results) send_args = if results.first && results.first.kind_of?(Hash) [:[]] else [] end if [:one] results.inject({}) do |hash, r| key = r.send(*send_args, [:group_by]) hash[key] = r hash end else results.inject({}) do |hash, r| key = r.send(*send_args, [:group_by]) (hash[key] ||= []).push(r) hash end end elsif [:array_to_hash] Array(results).inject({}) do |hash, r| hash[r[0]] = r[1] hash end else results end end |
.options(hash) ⇒ Object
12 13 14 |
# File 'lib/datasource/attributes/loader.rb', line 12 def (hash) self..merge!(hash) end |