Class: Rabl::MultiBuilder
- Inherits:
-
Object
- Object
- Rabl::MultiBuilder
- Includes:
- Helpers
- Defined in:
- lib/rabl/multi_builder.rb
Instance Method Summary collapse
-
#initialize(data, settings = {}, options = {}) ⇒ MultiBuilder
constructor
Constructs a new MultiBuilder given the data and options.
-
#to_a ⇒ Object
Returns the result of all of the builders as an array.
Methods included from Helpers
#collection_root_name, #context_scope, #data_name, #data_object, #data_object_attribute, #determine_object_root, #fetch_result_from_cache, #is_collection?, #is_name_value?, #is_object?, #object_root_name, #object_to_engine, #template_cache_configured?, #view_path, #write_result_to_cache
Constructor Details
#initialize(data, settings = {}, options = {}) ⇒ MultiBuilder
Constructs a new MultiBuilder given the data and options. The options will be re-used for all Rabl::Builders. Rabl::MultiBuilder.new([#<User …>, #<User …>, …], { :format => ‘json’, :child_root => true })
8 9 10 11 12 13 14 15 |
# File 'lib/rabl/multi_builder.rb', line 8 def initialize(data, settings = {}, = {}) @data = data @settings = settings @options = @builders = [] @engine_to_builder = {} @cache_key_to_engine = {} end |
Instance Method Details
#to_a ⇒ Object
Returns the result of all of the builders as an array
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rabl/multi_builder.rb', line 18 def to_a generate_builders if template_cache_configured? && Rabl.configuration.use_read_multi map_engines_to_builders read_cache_results replace_engines_with_cache_results end result = @builders.map(&:to_hash) result = result.map(&:presence).compact if Rabl.configuration.exclude_empty_values_in_collections result end |