Module: JsonDumper::Helper
- Defined in:
- lib/json_dumper/helper.rb
Instance Method Summary collapse
- #dumper_fetch(delayed, camelcase: true) ⇒ Object
- #dumper_json(hash) ⇒ Object
- #render_dumper_json(hash) ⇒ Object
Instance Method Details
#dumper_fetch(delayed, camelcase: true) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/json_dumper/helper.rb', line 18 def dumper_fetch(delayed, camelcase: true) preload_hash = delayed.klass.send("#{delayed.method_name}_preload") preloader.preload(delayed.entity,preload_hash) result = if delayed.named_args.empty? delayed.klass.send(delayed.method_name, delayed.entity, *delayed.positional_args) else delayed.klass.send(delayed.method_name, delayed.entity, *delayed.positional_args, **delayed.named_args) end if camelcase result = KeyTransformer.keys_to_camelcase(result) end result end |
#dumper_json(hash) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/json_dumper/helper.rb', line 7 def dumper_json(hash) result = hash.map do |k, v| if v.is_a?(JsonDumper::Delayed) [k, dumper_fetch(v, camelcase: false)] else [k, v] end end.to_h KeyTransformer.keys_to_camelcase(result) end |
#render_dumper_json(hash) ⇒ Object
3 4 5 |
# File 'lib/json_dumper/helper.rb', line 3 def render_dumper_json(hash) render json: dumper_json(hash) end |