Module: RedSnow

Includes:
Binding
Defined in:
lib/redsnow/object.rb,
lib/redsnow.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, 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.3.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#optionsObject

Parse options



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

def options
  @options
end

Class Method Details

.parse(rawBlueprint, options = 0) ⇒ ParseResult

parse

parsing API Blueprint into Ruby objects

Parameters:

  • rawBlueprint (String)

    API Blueprint

  • options (Number) (defaults to: 0)

    Parsing Options

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/redsnow.rb', line 45

def self.parse(rawBlueprint, options = 0)

  raise ArgumentError.new("Expected string value") unless rawBlueprint.is_a?(String)

  blueprintOptions = self.parse_options(options)

  blueprint = FFI::MemoryPointer.new :pointer
  sourcemap = FFI::MemoryPointer.new :pointer
  report = FFI::MemoryPointer.new :pointer

  RedSnow::Binding.sc_c_parse(rawBlueprint, blueprintOptions, report, blueprint, sourcemap)

  blueprint = blueprint.get_pointer(0)
  sourcemap = sourcemap.get_pointer(0)
  report = report.get_pointer(0)

  parseResult = ParseResult.new(report, blueprint, sourcemap)

  return parseResult
ensure
  RedSnow::Binding.sc_sm_blueprint_free(sourcemap)
  RedSnow::Binding.sc_blueprint_free(blueprint)
  RedSnow::Binding.sc_report_free(report)
end

.parse_options(options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/redsnow.rb', line 17

def self.parse_options(options)
  # Parse Options
  unless options.is_a?(Numeric)
    opt = 0
    if options.has_key?(REQUIRE_BLUEPRINT_NAME_OPTION_KEY)
      if options[REQUIRE_BLUEPRINT_NAME_OPTION_KEY] === true
        opt = opt | (1 << 1)
      end
    end

    if options.has_key?(EXPORT_SOURCEMAP_OPTION_KEY)
      if options[EXPORT_SOURCEMAP_OPTION_KEY] === true
        opt = opt | (1 << 2)
      end
    end

    return opt
  else
    return options
  end
end