Sha256: 7a66a5a32a32bcf1cdc1f1d34c2382600eed2e7736984250af92931e2f570a09

Contents?: true

Size: 848 Bytes

Versions: 4

Compression:

Stored size: 848 Bytes

Contents

require 'supa/commands/attribute'
require 'supa/commands/object'
require 'supa/commands/namespace'
require 'supa/commands/collection'
require 'supa/commands/polymorphic'

module Supa
  class Builder
    COMMANDS = %w(attribute object namespace collection polymorphic).freeze

    COMMANDS.each do |command|
      klass = Supa::Commands.const_get(command.capitalize)

      define_method command do |name, options = {}, &block|
        klass.new(context: context,
                  tree: tree,
                  name: name,
                  options: options,
                  &block).represent
      end
    end

    def initialize(context:, tree:)
      @context = context
      @tree = tree
    end

    def to_hash
      tree.to_hash
    end

    def to_json
      to_hash.to_json
    end

    private
    attr_reader :context, :tree
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
supa-0.1.4 lib/supa/builder.rb
supa-0.1.3 lib/supa/builder.rb
supa-0.1.2 lib/supa/builder.rb
supa-0.1.1 lib/supa/builder.rb