lib/praxis/blueprint.rb in praxis-2.0.pre.29 vs lib/praxis/blueprint.rb in praxis-2.0.pre.30

- old
+ new

@@ -1,9 +1,21 @@ # frozen_string_literal: true module Praxis class Blueprint + class DSLCompiler < Attributor::HashDSLCompiler + # group DSL is meant to group a subset of attributes in the media type (instead of presenting all things flat) + # It will create a normal attribute, but as a BlueprintAttributeGroup, rather than a Struct, so that we can more easily + # pass in objects that respond to the right methods, and avoid a Struct loading them all in hash keys. + # For example, if there are computationally intensive attributes in the subset, we want to make sure those functions + # aren't invoked by just merely loading, and only really invoked when we've asked to render them + # It takes the name of the group, and passes the attributes block that needs to be a subset of the MediaType where the group resides + def group(name, **options, &block) + attribute(name, Praxis::BlueprintAttributeGroup.for(target.options[:reference]), **options, &block) + end + end + # Simple helper class that can parse the `attribute :foobar` dsl into # an equivalent structure hash. Example: # do # attribute :one # attribute :complex do @@ -89,10 +101,10 @@ raise "Reference mismatch in #{inspect}. Given :reference option #{opts[:reference].inspect}, while using #{reference.inspect}" if opts.key?(:reference) && opts[:reference] != reference opts[:reference] = (reference || self) - @options.merge!(opts) + @options.merge!(opts.merge(dsl_compiler: DSLCompiler)) @block = block return @attribute end