class Skemata::DSL

Attributes

node[R]

Public Class Methods

draw(opts = {}, &block) click to toggle source

Draw a schema.org node. Creates a new DSL class for each child node. @param opts = {} [Hash] Options hash

root_object (required): Object you wish to serialize
type        (required): schema.org type
is_root     (optional): Is this the top level object

@param &block [Block] DSL schema definition

@return [String] schema.org JSON structure

# File lib/skemata/dsl.rb, line 18
def draw(opts = {}, &block)
  dsl = new(Node.new(opts))
  dsl.instance_eval(&block)
  opts.fetch(:is_root, true) ? dsl.node.data.to_json : dsl.node.data
end
new(node) click to toggle source

Prepares DSL instance by assigning Node @param node [Node] Data object

@return [DSL] A DSL class.

# File lib/skemata/dsl.rb, line 30
def initialize(node)
  raise(
    ArgumentError, 'DSL must be provided with a Skemata::Node type!'
  ) unless node.is_a?(Node)

  @node = node
end

Public Instance Methods

method_missing(name, *args, &block) click to toggle source

rubocop:disable Style/MethodMissing TODO: special token so we can define respond_to_missing?

# File lib/skemata/dsl.rb, line 40
def method_missing(name, *args, &block)
  node.decorate(name, *args, &block)
end
nested(*args) click to toggle source

Delegator to NodeMethodChain.new @param *args [varargs]

@return [NodeMethodChain]

# File lib/skemata/dsl.rb, line 50
def nested(*args)
  NodeMethodChain.new(args)
end