Module: RedSnow

Includes:
Binding
Defined in:
lib/redsnow.rb,
lib/redsnow/object.rb,
lib/redsnow/binding.rb,
lib/redsnow/version.rb,
lib/redsnow/blueprint.rb,
lib/redsnow/sourcemap.rb,
lib/redsnow/parseresult.rb

Overview

The classes in this module should be 1:1 with the Snow Crash Blueprint sourcemap counterparts (github.com/apiaryio/snowcrash/blob/master/src/BlueprintSourcemap.h).

Defined Under Namespace

Modules: Binding, Memory, Sourcemap Classes: Action, Blueprint, BlueprintNode, ErrorCodes, Headers, KeyValueCollection, Location, Metadata, NamedBlueprintNode, Object, Parameter, Parameters, ParseResult, Payload, ReferenceNode, Resource, ResourceGroup, TransactionExample, WarningCodes

Constant Summary collapse

EXPORT_SOURCEMAP_OPTION_KEY =

Options

:exportSourcemap
REQUIRE_BLUEPRINT_NAME_OPTION_KEY =
:requireBlueprintName
VERSION =

Gem version

'0.4.4'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#optionsObject

Parse options



17
18
19
# File 'lib/redsnow.rb', line 17

def options
  @options
end

Class Method Details

.parse(raw_blueprint, options = 0) ⇒ ParseResult

parse

parsing API Blueprint into Ruby objects

Parameters:

  • raw_blueprint (String)

    API Blueprint

  • options (Number) (defaults to: 0)

    Parsing Options

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/redsnow.rb', line 36

def self.parse(raw_blueprint, options = 0)
  fail ArgumentError, 'Expected string value' unless raw_blueprint.is_a?(String)

  blueprint_options = parse_options(options)

  parse_result = FFI::MemoryPointer.new :pointer

  RedSnow::Binding.drafter_c_parse(raw_blueprint, blueprint_options, parse_result)

  parse_result = parse_result.get_pointer(0)

  ParseResult.new(parse_result.null? ? nil : parse_result.read_string)
ensure

  RedSnow::Memory.free(parse_result)
end

.parse_options(options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/redsnow.rb', line 18

def self.parse_options(options)
  # Parse Options
  if options.is_a?(Numeric)
    return options
  else
    opt = 0
    opt |= (1 << 1) if options[REQUIRE_BLUEPRINT_NAME_OPTION_KEY]
    opt |= (1 << 2) if options[EXPORT_SOURCEMAP_OPTION_KEY]
    return opt
  end
end