class Praxis::Blueprint::FieldsetParser

Simple helper class that can parse the ‘attribute :foobar` dsl into an equivalent structure hash. Example: do

 attribute :one
 attribute :complex do
   attribute :sub1
 end
end

is parsed as: { one: true, complex: { sub1: true} }

Public Class Methods

new(&block) click to toggle source
# File lib/praxis/blueprint.rb, line 28
def initialize(&block)
  @hash = nil
  @block = block
end

Public Instance Methods

attribute(name, **args, &block) click to toggle source
# File lib/praxis/blueprint.rb, line 33
def attribute(name, **args, &block)
  unless args.empty?
    raise "Default fieldset definitions do not accept parameters (got: #{args})" \
          "If you're upgrading from a previous version of Praxis and still using the view :default " \
          "block syntax, make sure you don't use any view: X parameters when you define the attributes " \
          '(expand them explicitly if you want deeper structure)' \
          "The offending view with parameters is defined in:\n#{Kernel.caller.first}"
  end
  @hash[name] = block_given? ? FieldsetParser.new(&block).fieldset : true
end
fieldset() click to toggle source
# File lib/praxis/blueprint.rb, line 44
def fieldset
  return @hash if @hash

  # Lazy eval
  @hash = {}
  instance_eval(&@block)
  @hash
end