Sha256: b9dc926babb1a1f982e9ebdf47081efeec50b85a097c505f8c4c2b23e30aefbe
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
require "redsnow/version" require "redsnow/binding" require "redsnow/blueprint" require "redsnow/sourcemap" require "redsnow/parseresult" require "ffi" module RedSnow include Binding # Options EXPORT_SOURCEMAP_OPTION_KEY = :'exportSourcemap' REQUIRE_BLUEPRINT_NAME_OPTION_KEY = :'requireBlueprintName' # Parse options attr_accessor :options 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] opt = opt | (1 << 1) end end if options.has_key?(EXPORT_SOURCEMAP_OPTION_KEY) if options[EXPORT_SOURCEMAP_OPTION_KEY] opt = opt | (1 << 2) end end return opt else return options end end # parse # parsing API Blueprint into Ruby objects # @param rawBlueprint [String] API Blueprint # @param options [Number] Parsing Options # # @return [ParseResult] 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redsnow-0.3.2 | lib/redsnow.rb |