redsnow 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.gitmodules +3 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/Rakefile +36 -0
- data/Vagrantfile +20 -0
- data/ext/snowcrash/Makefile +64 -0
- data/ext/snowcrash/Vagrantfile +20 -0
- data/ext/snowcrash/bin/snowcrash +0 -0
- data/ext/snowcrash/common.gypi +163 -0
- data/ext/snowcrash/config.gypi +10 -0
- data/ext/snowcrash/config.mk +5 -0
- data/ext/snowcrash/configure +213 -0
- data/ext/snowcrash/provisioning.sh +15 -0
- data/ext/snowcrash/snowcrash.gyp +141 -0
- data/ext/snowcrash/src/ActionParser.h +503 -0
- data/ext/snowcrash/src/AssetParser.h +215 -0
- data/ext/snowcrash/src/BlockUtility.h +186 -0
- data/ext/snowcrash/src/Blueprint.h +283 -0
- data/ext/snowcrash/src/BlueprintParser.h +347 -0
- data/ext/snowcrash/src/BlueprintParserCore.h +190 -0
- data/ext/snowcrash/src/BlueprintSection.h +140 -0
- data/ext/snowcrash/src/BlueprintUtility.h +126 -0
- data/ext/snowcrash/src/CBlueprint.cc +600 -0
- data/ext/snowcrash/src/CBlueprint.h +354 -0
- data/ext/snowcrash/src/CSourceAnnotation.cc +140 -0
- data/ext/snowcrash/src/CSourceAnnotation.h +106 -0
- data/ext/snowcrash/src/CodeBlockUtility.h +189 -0
- data/ext/snowcrash/src/DescriptionSectionUtility.h +156 -0
- data/ext/snowcrash/src/HTTP.cc +46 -0
- data/ext/snowcrash/src/HTTP.h +105 -0
- data/ext/snowcrash/src/HeaderParser.h +289 -0
- data/ext/snowcrash/src/ListBlockUtility.h +273 -0
- data/ext/snowcrash/src/ListUtility.h +95 -0
- data/ext/snowcrash/src/MarkdownBlock.cc +176 -0
- data/ext/snowcrash/src/MarkdownBlock.h +93 -0
- data/ext/snowcrash/src/MarkdownParser.cc +266 -0
- data/ext/snowcrash/src/MarkdownParser.h +88 -0
- data/ext/snowcrash/src/ParameterDefinitonParser.h +570 -0
- data/ext/snowcrash/src/ParametersParser.h +252 -0
- data/ext/snowcrash/src/Parser.cc +71 -0
- data/ext/snowcrash/src/Parser.h +29 -0
- data/ext/snowcrash/src/ParserCore.cc +120 -0
- data/ext/snowcrash/src/ParserCore.h +82 -0
- data/ext/snowcrash/src/PayloadParser.h +672 -0
- data/ext/snowcrash/src/Platform.h +54 -0
- data/ext/snowcrash/src/RegexMatch.h +32 -0
- data/ext/snowcrash/src/ResourceGroupParser.h +195 -0
- data/ext/snowcrash/src/ResourceParser.h +584 -0
- data/ext/snowcrash/src/SectionUtility.h +142 -0
- data/ext/snowcrash/src/Serialize.cc +52 -0
- data/ext/snowcrash/src/Serialize.h +69 -0
- data/ext/snowcrash/src/SerializeJSON.cc +601 -0
- data/ext/snowcrash/src/SerializeJSON.h +21 -0
- data/ext/snowcrash/src/SerializeYAML.cc +336 -0
- data/ext/snowcrash/src/SerializeYAML.h +21 -0
- data/ext/snowcrash/src/SourceAnnotation.h +177 -0
- data/ext/snowcrash/src/StringUtility.h +109 -0
- data/ext/snowcrash/src/SymbolTable.h +83 -0
- data/ext/snowcrash/src/UriTemplateParser.cc +195 -0
- data/ext/snowcrash/src/UriTemplateParser.h +243 -0
- data/ext/snowcrash/src/Version.h +39 -0
- data/ext/snowcrash/src/csnowcrash.cc +23 -0
- data/ext/snowcrash/src/csnowcrash.h +38 -0
- data/ext/snowcrash/src/posix/RegexMatch.cc +99 -0
- data/ext/snowcrash/src/snowcrash.cc +18 -0
- data/ext/snowcrash/src/snowcrash.h +41 -0
- data/ext/snowcrash/src/snowcrash/snowcrash.cc +170 -0
- data/ext/snowcrash/src/win/RegexMatch.cc +78 -0
- data/ext/snowcrash/sundown/CONTRIBUTING.md +10 -0
- data/ext/snowcrash/sundown/Makefile +83 -0
- data/ext/snowcrash/sundown/Makefile.win +33 -0
- data/ext/snowcrash/sundown/examples/smartypants.c +72 -0
- data/ext/snowcrash/sundown/examples/sundown.c +80 -0
- data/ext/snowcrash/sundown/html/houdini.h +37 -0
- data/ext/snowcrash/sundown/html/houdini_href_e.c +108 -0
- data/ext/snowcrash/sundown/html/houdini_html_e.c +84 -0
- data/ext/snowcrash/sundown/html/html.c +647 -0
- data/ext/snowcrash/sundown/html/html.h +77 -0
- data/ext/snowcrash/sundown/html/html_smartypants.c +389 -0
- data/ext/snowcrash/sundown/html_block_names.txt +25 -0
- data/ext/snowcrash/sundown/src/autolink.c +297 -0
- data/ext/snowcrash/sundown/src/autolink.h +51 -0
- data/ext/snowcrash/sundown/src/buffer.c +225 -0
- data/ext/snowcrash/sundown/src/buffer.h +96 -0
- data/ext/snowcrash/sundown/src/html_blocks.h +206 -0
- data/ext/snowcrash/sundown/src/markdown.c +2701 -0
- data/ext/snowcrash/sundown/src/markdown.h +147 -0
- data/ext/snowcrash/sundown/src/src_map.c +200 -0
- data/ext/snowcrash/sundown/src/src_map.h +58 -0
- data/ext/snowcrash/sundown/src/stack.c +81 -0
- data/ext/snowcrash/sundown/src/stack.h +29 -0
- data/ext/snowcrash/sundown/sundown.def +20 -0
- data/ext/snowcrash/tools/gyp/AUTHORS +11 -0
- data/ext/snowcrash/tools/gyp/DEPS +24 -0
- data/ext/snowcrash/tools/gyp/OWNERS +1 -0
- data/ext/snowcrash/tools/gyp/PRESUBMIT.py +120 -0
- data/ext/snowcrash/tools/gyp/buildbot/buildbot_run.py +190 -0
- data/ext/snowcrash/tools/gyp/codereview.settings +10 -0
- data/ext/snowcrash/tools/gyp/data/win/large-pdb-shim.cc +12 -0
- data/ext/snowcrash/tools/gyp/gyp +8 -0
- data/ext/snowcrash/tools/gyp/gyp.bat +5 -0
- data/ext/snowcrash/tools/gyp/gyp_main.py +18 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSNew.py +340 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSProject.py +208 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSSettings.py +1063 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSToolFile.py +58 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUserFile.py +147 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUtil.py +267 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSVersion.py +409 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.py +537 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/common.py +521 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/common.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/easy_xml.py +157 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/flock_tool.py +49 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.py +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/android.py +1069 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/cmake.py +1143 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/dump_dependency_json.py +81 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/eclipse.py +335 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypd.py +87 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypsh.py +56 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.py +2181 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/msvs.py +3335 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/ninja.py +2156 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.py +1224 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/input.py +2809 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/input.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/mac_tool.py +510 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/msvs_emulation.py +972 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/ninja_syntax.py +160 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/ordered_dict.py +289 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/win_tool.py +292 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.py +1440 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.py +2889 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xml_fix.py +69 -0
- data/ext/snowcrash/tools/gyp/pylintrc +307 -0
- data/ext/snowcrash/tools/gyp/samples/samples +81 -0
- data/ext/snowcrash/tools/gyp/samples/samples.bat +5 -0
- data/ext/snowcrash/tools/gyp/setup.py +19 -0
- data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.pbfilespec +27 -0
- data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.xclangspec +226 -0
- data/ext/snowcrash/tools/gyp/tools/emacs/gyp.el +252 -0
- data/ext/snowcrash/tools/gyp/tools/graphviz.py +100 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_gyp.py +155 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_sln.py +168 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_vcproj.py +329 -0
- data/ext/snowcrash/tools/homebrew/snowcrash.rb +11 -0
- data/ext/snowcrash/vcbuild.bat +184 -0
- data/lib/redsnow.rb +31 -0
- data/lib/redsnow/binding.rb +132 -0
- data/lib/redsnow/blueprint.rb +365 -0
- data/lib/redsnow/object.rb +18 -0
- data/lib/redsnow/parseresult.rb +107 -0
- data/lib/redsnow/version.rb +4 -0
- data/provisioning.sh +20 -0
- data/redsnow.gemspec +35 -0
- data/test/_helper.rb +15 -0
- data/test/fixtures/sample-api-ast.json +97 -0
- data/test/fixtures/sample-api.apib +20 -0
- data/test/redsnow_binding_test.rb +35 -0
- data/test/redsnow_parseresult_test.rb +50 -0
- data/test/redsnow_test.rb +285 -0
- metadata +358 -0
@@ -0,0 +1,184 @@
|
|
1
|
+
@echo off
|
2
|
+
|
3
|
+
@rem Attribution Notice
|
4
|
+
@rem ------------------
|
5
|
+
@rem This file uses parts of Node.js `vcbuild.bat`.
|
6
|
+
@rem Please refer to https://github.com/joyent/node.
|
7
|
+
|
8
|
+
cd %~dp0
|
9
|
+
|
10
|
+
if /i "%1"=="help" goto help
|
11
|
+
if /i "%1"=="--help" goto help
|
12
|
+
if /i "%1"=="-help" goto help
|
13
|
+
if /i "%1"=="/help" goto help
|
14
|
+
if /i "%1"=="?" goto help
|
15
|
+
if /i "%1"=="-?" goto help
|
16
|
+
if /i "%1"=="--?" goto help
|
17
|
+
if /i "%1"=="/?" goto help
|
18
|
+
|
19
|
+
@rem Process arguments.
|
20
|
+
set config=Release
|
21
|
+
set target=Build
|
22
|
+
set target_arch=ia32
|
23
|
+
set noprojgen=
|
24
|
+
set nobuild=
|
25
|
+
set test=
|
26
|
+
|
27
|
+
:next-arg
|
28
|
+
if "%1"=="" goto args-done
|
29
|
+
if /i "%1"=="debug" set config=Debug&goto arg-ok
|
30
|
+
if /i "%1"=="release" set config=Release&goto arg-ok
|
31
|
+
if /i "%1"=="clean" set target=Clean&goto arg-ok
|
32
|
+
if /i "%1"=="ia32" set target_arch=ia32&goto arg-ok
|
33
|
+
if /i "%1"=="x86" set target_arch=ia32&goto arg-ok
|
34
|
+
if /i "%1"=="x64" set target_arch=x64&goto arg-ok
|
35
|
+
if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok
|
36
|
+
if /i "%1"=="nobuild" set nobuild=1&goto arg-ok
|
37
|
+
if /i "%1"=="test" set test=test&goto arg-ok
|
38
|
+
if /i "%1"=="inttest" set inttest=1&goto arg-ok
|
39
|
+
if /i "%1"=="MSVC2012" set GYP_MSVS_VERSION=2012&goto arg-ok
|
40
|
+
if /i "%1"=="MSVC2010" set GYP_MSVS_VERSION=2010&goto arg-ok
|
41
|
+
if /i "%1"=="MSVC2008" set GYP_MSVS_VERSION=2008&goto arg-ok
|
42
|
+
|
43
|
+
echo Warning: ignoring invalid command line option `%1`.
|
44
|
+
|
45
|
+
:arg-ok
|
46
|
+
shift
|
47
|
+
goto next-arg
|
48
|
+
|
49
|
+
:args-done
|
50
|
+
if "%config%"=="Debug" set debug_arg=--debug
|
51
|
+
|
52
|
+
:project-gen
|
53
|
+
@rem Skip project generation if requested.
|
54
|
+
if defined noprojgen goto msbuild
|
55
|
+
if "%GYP_MSVS_VERSION%"=="" set GYP_MSVS_VERSION=2012
|
56
|
+
|
57
|
+
@rem Generate the VS project.
|
58
|
+
SETLOCAL
|
59
|
+
if defined VS100COMNTOOLS call "%VS100COMNTOOLS%\VCVarsQueryRegistry.bat"
|
60
|
+
if defined inttest python configure %debug_arg% --dest-cpu=%target_arch% --include-integration-tests
|
61
|
+
if not defined inttest python configure %debug_arg% --dest-cpu=%target_arch%
|
62
|
+
if errorlevel 1 goto create-msvs-files-failed
|
63
|
+
if not exist build/snowcrash.sln goto create-msvs-files-failed
|
64
|
+
echo Project files generated.
|
65
|
+
ENDLOCAL
|
66
|
+
|
67
|
+
@rem Skip to the end for now
|
68
|
+
@rem goto exit
|
69
|
+
|
70
|
+
:msbuild
|
71
|
+
@rem Skip project generation if requested.
|
72
|
+
if defined nobuild goto exit
|
73
|
+
if "%GYP_MSVS_VERSION%"=="2010" goto vc-set-2010
|
74
|
+
if "%GYP_MSVS_VERSION%"=="2008" goto vc-set-2008
|
75
|
+
|
76
|
+
@rem Look for Visual Studio 2012
|
77
|
+
if not defined VS110COMNTOOLS goto vc-set-2010
|
78
|
+
if not exist "%VS110COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2010
|
79
|
+
call "%VS110COMNTOOLS%\..\..\vc\vcvarsall.bat"
|
80
|
+
if not defined VCINSTALLDIR goto msbuild-not-found
|
81
|
+
goto msbuild-found
|
82
|
+
|
83
|
+
:vc-set-2010
|
84
|
+
if not defined VS100COMNTOOLS goto vc-set-2008
|
85
|
+
if not exist "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2008
|
86
|
+
call "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat"
|
87
|
+
if not defined VCINSTALLDIR goto msbuild-not-found
|
88
|
+
goto msbuild-found
|
89
|
+
|
90
|
+
:vc-set-2008
|
91
|
+
if not defined VS90COMNTOOLS goto msbuild-not-found
|
92
|
+
if not exist "%VS90COMNTOOLS%\..\..\vc\vcvarsall.bat" goto msbuild-not-found
|
93
|
+
call "%VS90COMNTOOLS%\..\..\vc\vcvarsall.bat"
|
94
|
+
if not defined VCINSTALLDIR goto msbuild-not-found
|
95
|
+
goto msbuild-found
|
96
|
+
|
97
|
+
:msbuild-not-found
|
98
|
+
echo Build skipped. To build, this file needs to run from VS cmd prompt.
|
99
|
+
goto exit
|
100
|
+
|
101
|
+
:msbuild-found
|
102
|
+
@rem Build the sln with msbuild.
|
103
|
+
@rem Refer to http://msdn.microsoft.com/en-us/library/ms164311.aspx
|
104
|
+
echo Building Snow Crash...
|
105
|
+
msbuild build/snowcrash.sln /m /clp:NoSummary;NoItemAndPropertyList;Verbosity=normal /nologo /property:Configuration=%config%
|
106
|
+
if errorlevel 1 goto exit
|
107
|
+
|
108
|
+
:run
|
109
|
+
@rem Run tests if requested.
|
110
|
+
if "%test%"=="" goto intigration-test
|
111
|
+
echo Running tests...
|
112
|
+
.\build\%config%\test-libsnowcrash.exe
|
113
|
+
|
114
|
+
:intigration-test
|
115
|
+
if defined inttest goto run-integration-test
|
116
|
+
|
117
|
+
@rem All Done
|
118
|
+
goto exit
|
119
|
+
|
120
|
+
:run-integration-test
|
121
|
+
if "%config%"=="Debug" (
|
122
|
+
SET "Replacement= ENV['PATH'] = "../../build/Debug""
|
123
|
+
goto :run-cucumber
|
124
|
+
)
|
125
|
+
SET "Replacement= ENV['PATH'] = "../../build/Release""
|
126
|
+
goto :run-cucumber
|
127
|
+
|
128
|
+
:run-cucumber
|
129
|
+
SET "file=features\support\env-win.rb"
|
130
|
+
if exist "%file%" goto env-exist
|
131
|
+
SETLOCAL ENABLEDELAYEDEXPANSION
|
132
|
+
SET "line=require 'aruba/cucumber'"
|
133
|
+
ECHO !line! >"%file%"
|
134
|
+
SET "line=require 'rbconfig'"
|
135
|
+
ECHO !line! >>"%file%"
|
136
|
+
SET "line=Before do"
|
137
|
+
ECHO !line! >>"%file%"
|
138
|
+
SET "line= @dirs << "../../features/fixtures""
|
139
|
+
ECHO !line! >>"%file%"
|
140
|
+
SET "line= case RbConfig::CONFIG['host_os']"
|
141
|
+
ECHO !line! >>"%file%"
|
142
|
+
SET "line= when /mswin|msys|mingw|cygwin|bccwin|wince|emc/"
|
143
|
+
ECHO !line! >>"%file%"
|
144
|
+
ECHO !Replacement! >>"%file%"
|
145
|
+
SET "line=end"
|
146
|
+
ECHO !line! >>"%file%"
|
147
|
+
SET "line=end"
|
148
|
+
ECHO !line! >>"%file%"
|
149
|
+
ENDLOCAL
|
150
|
+
|
151
|
+
bundle exec cucumber
|
152
|
+
goto exit
|
153
|
+
|
154
|
+
:env-exist
|
155
|
+
SET /a Line#ToSearch=7
|
156
|
+
(FOR /f "tokens=1*delims=:" %%a IN ('findstr /n "^" "%file%"') DO (
|
157
|
+
SET "Line=%%b"
|
158
|
+
IF %%a equ %Line#ToSearch% SET "Line=%Replacement%"
|
159
|
+
SETLOCAL ENABLEDELAYEDEXPANSION
|
160
|
+
ECHO(!Line!)
|
161
|
+
ENDLOCAL
|
162
|
+
)>"%file%.new"
|
163
|
+
MOVE "%file%.new" "%file%" >nul
|
164
|
+
|
165
|
+
bundle exec cucumber
|
166
|
+
goto exit
|
167
|
+
|
168
|
+
:create-msvs-files-failed
|
169
|
+
echo Failed to create vc project files.
|
170
|
+
goto exit
|
171
|
+
|
172
|
+
:help
|
173
|
+
echo vcbuild.bat [debug/release] [test] [clean] [noprojgen] [nobuild] [x86/x64] [inttest] [MSVC2008/MSVC2010/MSVC2012]
|
174
|
+
echo Examples:
|
175
|
+
echo vcbuild.bat : builds release build
|
176
|
+
echo vcbuild.bat nobuild : generate MSVS project files only
|
177
|
+
echo vcbuild.bat debug : builds debug build
|
178
|
+
echo vcbuild.bat test : builds debug build and runs tests
|
179
|
+
echo vcbuild.bat inttest : include integration tests
|
180
|
+
echo vcbuild.bat MSVC2012 : indicate target solution's version, could also define as MSVC2008 , MSVC2010 , MSVC2012
|
181
|
+
goto exit
|
182
|
+
|
183
|
+
:exit
|
184
|
+
goto :EOF
|
data/lib/redsnow.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "redsnow/version"
|
2
|
+
require "redsnow/binding"
|
3
|
+
require "redsnow/blueprint"
|
4
|
+
require "redsnow/parseresult"
|
5
|
+
require "ffi"
|
6
|
+
|
7
|
+
module RedSnow
|
8
|
+
include Binding
|
9
|
+
# parse
|
10
|
+
# parsing API Blueprint into Ruby objects
|
11
|
+
# @param rawBlueprint [String] API Blueprint
|
12
|
+
# @param options [Number] Parsing Options
|
13
|
+
#
|
14
|
+
# @return [ParseResult]
|
15
|
+
def self.parse(rawBlueprint, options = 0)
|
16
|
+
blueprint = FFI::MemoryPointer.new :pointer
|
17
|
+
result = FFI::MemoryPointer.new :pointer
|
18
|
+
ret = RedSnow::Binding.sc_c_parse(rawBlueprint, options, result, blueprint)
|
19
|
+
|
20
|
+
blueprint = blueprint.get_pointer(0)
|
21
|
+
result = result.get_pointer(0)
|
22
|
+
|
23
|
+
parseResult = ParseResult.new(blueprint, result)
|
24
|
+
|
25
|
+
return parseResult
|
26
|
+
ensure
|
27
|
+
RedSnow::Binding.sc_blueprint_free(blueprint)
|
28
|
+
RedSnow::Binding.sc_result_free(result)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require "ffi"
|
2
|
+
|
3
|
+
module RedSnow
|
4
|
+
# C-binding with Snow Crash Library using [FFI](https://github.com/ffi/ffi)
|
5
|
+
# @see https://github.com/apiaryio/snowcrash/blob/master/src/csnowcrash.cc
|
6
|
+
# @see https://github.com/apiaryio/snowcrash/blob/master/src/CBlueprint.cc
|
7
|
+
module Binding
|
8
|
+
extend FFI::Library
|
9
|
+
|
10
|
+
prefix = "lib.target/"
|
11
|
+
if FFI::Platform.mac?
|
12
|
+
prefix = ""
|
13
|
+
end
|
14
|
+
|
15
|
+
ffi_lib File.expand_path("../../../ext/snowcrash/build/out/Release/#{prefix}libsnowcrash.#{FFI::Platform::LIBSUFFIX}", __FILE__)
|
16
|
+
# @see https://github.com/apiaryio/snowcrash/blob/master/src/BlueprintParserCore.h#L31
|
17
|
+
enum :option, [
|
18
|
+
:render_descriptions_option,
|
19
|
+
:require_blueprint_name_option
|
20
|
+
]
|
21
|
+
|
22
|
+
attach_function("sc_c_parse", "sc_c_parse", [ :string, :option, :pointer, :pointer ], :int)
|
23
|
+
|
24
|
+
attach_function("sc_blueprint_free", "sc_blueprint_free", [ :pointer ], :void)
|
25
|
+
attach_function("sc_blueprint_name", "sc_blueprint_name", [ :pointer ], :string)
|
26
|
+
attach_function("sc_blueprint_description", "sc_blueprint_description", [ :pointer ], :string)
|
27
|
+
|
28
|
+
attach_function("sc_metadata_collection_handle", "sc_metadata_collection_handle", [ :pointer ], :pointer)
|
29
|
+
attach_function("sc_metadata_collection_size", "sc_metadata_collection_size", [ :pointer ], :int)
|
30
|
+
|
31
|
+
attach_function("sc_metadata_handle", "sc_metadata_handle", [ :pointer, :int ], :pointer)
|
32
|
+
attach_function("sc_metadata_key", "sc_metadata_key", [ :pointer ], :string)
|
33
|
+
attach_function("sc_metadata_value", "sc_metadata_value",[ :pointer ], :string)
|
34
|
+
|
35
|
+
attach_function("sc_resource_groups_collection_handle", "sc_resource_groups_collection_handle", [ :pointer ], :pointer)
|
36
|
+
attach_function("sc_resource_groups_collection_size", "sc_resource_groups_collection_size", [ :pointer ], :int)
|
37
|
+
|
38
|
+
attach_function("sc_resource_groups_handle", "sc_resource_groups_handle", [ :pointer, :int ], :pointer)
|
39
|
+
attach_function("sc_resource_groups_name", "sc_resource_groups_name", [ :pointer ], :string)
|
40
|
+
attach_function("sc_resource_groups_description", "sc_resource_groups_description", [ :pointer ], :string)
|
41
|
+
|
42
|
+
attach_function("sc_resource_collection_handle", "sc_resource_collection_handle", [ :pointer ] , :pointer)
|
43
|
+
attach_function("sc_resource_collection_size", "sc_resource_collection_size", [ :pointer ], :int)
|
44
|
+
# Resource
|
45
|
+
attach_function("sc_resource_handle", "sc_resource_handle", [ :pointer, :int ] , :pointer)
|
46
|
+
attach_function("sc_resource_uritemplate", "sc_resource_uritemplate", [ :pointer ], :string)
|
47
|
+
attach_function("sc_resource_name", "sc_resource_name", [ :pointer ], :string)
|
48
|
+
attach_function("sc_resource_description", "sc_resource_description", [ :pointer ], :string)
|
49
|
+
|
50
|
+
attach_function("sc_payload_collection_handle_requests", "sc_payload_collection_handle_requests", [ :pointer ], :pointer)
|
51
|
+
attach_function("sc_payload_collection_handle_responses", "sc_payload_collection_handle_responses", [ :pointer ], :pointer)
|
52
|
+
attach_function("sc_payload_collection_size", "sc_payload_collection_size", [ :pointer ], :int)
|
53
|
+
# Resource.model
|
54
|
+
attach_function("sc_payload_handle", "sc_payload_handle", [ :pointer, :int ], :pointer)
|
55
|
+
attach_function("sc_payload_handle_resource", "sc_payload_handle_resource", [ :pointer ], :pointer)
|
56
|
+
attach_function("sc_payload_name", "sc_payload_name", [ :pointer ], :string)
|
57
|
+
attach_function("sc_payload_description", "sc_payload_description", [ :pointer ], :string)
|
58
|
+
attach_function("sc_payload_body", "sc_payload_body", [ :pointer ], :string)
|
59
|
+
attach_function("sc_payload_schema", "sc_payload_schema", [ :pointer ], :string)
|
60
|
+
|
61
|
+
attach_function("sc_parameter_collection_handle_payload", "sc_parameter_collection_handle_payload", [ :pointer ], :pointer)
|
62
|
+
attach_function("sc_parameter_collection_handle_resource", "sc_parameter_collection_handle_resource", [ :pointer ], :pointer)
|
63
|
+
attach_function("sc_parameter_collection_handle_action", "sc_parameter_collection_handle_action", [ :pointer ], :pointer)
|
64
|
+
attach_function("sc_parameter_collection_size", "sc_parameter_collection_size", [ :pointer ], :int)
|
65
|
+
|
66
|
+
# @see https://github.com/apiaryio/snowcrash/blob/master/src/Blueprint.h#L85
|
67
|
+
enum :parameter_use, [:undefined,
|
68
|
+
:optional,
|
69
|
+
:required,
|
70
|
+
]
|
71
|
+
|
72
|
+
attach_function("sc_parameter_handle", "sc_parameter_handle", [ :pointer, :int ], :pointer)
|
73
|
+
attach_function("sc_parameter_name", "sc_parameter_name", [ :pointer ], :string)
|
74
|
+
attach_function("sc_parameter_description", "sc_parameter_description", [ :pointer ], :string)
|
75
|
+
attach_function("sc_parameter_type", "sc_parameter_type", [ :pointer ], :string)
|
76
|
+
attach_function("sc_parameter_parameter_use", "sc_parameter_parameter_use", [ :pointer ], :parameter_use)
|
77
|
+
attach_function("sc_parameter_default_value", "sc_parameter_default_value", [ :pointer ], :string)
|
78
|
+
attach_function("sc_parameter_example_value", "sc_parameter_example_value", [ :pointer ], :string)
|
79
|
+
|
80
|
+
attach_function("sc_value_collection_handle", "sc_value_collection_handle", [ :pointer], :pointer)
|
81
|
+
attach_function("sc_value_collection_size", "sc_value_collection_size", [ :pointer ], :int)
|
82
|
+
|
83
|
+
attach_function("sc_value_handle", "sc_value_handle", [ :pointer, :int ], :pointer)
|
84
|
+
attach_function("sc_value_string", "sc_value_string", [ :pointer], :string)
|
85
|
+
|
86
|
+
attach_function("sc_header_collection_handle_payload", "sc_header_collection_handle_payload", [ :pointer ], :pointer)
|
87
|
+
attach_function("sc_header_collection_handle_resource", "sc_header_collection_handle_resource", [ :pointer ], :pointer)
|
88
|
+
attach_function("sc_header_collection_handle_action", "sc_header_collection_handle_action", [ :pointer ], :pointer)
|
89
|
+
attach_function("sc_header_collection_size", "sc_header_collection_size", [ :pointer ], :int)
|
90
|
+
|
91
|
+
attach_function("sc_header_handle", "sc_header_handle", [ :pointer, :int ], :pointer)
|
92
|
+
attach_function("sc_header_key", "sc_header_key", [ :pointer ], :string)
|
93
|
+
attach_function("sc_header_value", "sc_header_value", [ :pointer], :string)
|
94
|
+
|
95
|
+
attach_function("sc_action_collection_handle", "sc_action_collection_handle", [ :pointer ], :pointer)
|
96
|
+
attach_function("sc_action_collection_size", "sc_action_collection_size", [ :pointer], :int)
|
97
|
+
|
98
|
+
attach_function("sc_action_handle", "sc_action_handle", [ :pointer, :int ], :pointer)
|
99
|
+
attach_function("sc_action_httpmethod", "sc_action_httpmethod", [ :pointer], :string)
|
100
|
+
attach_function("sc_action_name", "sc_action_name", [ :pointer], :string)
|
101
|
+
attach_function("sc_action_description", "sc_action_description", [ :pointer ], :string)
|
102
|
+
|
103
|
+
attach_function("sc_transaction_example_collection_handle", "sc_transaction_example_collection_handle", [ :pointer ], :pointer)
|
104
|
+
attach_function("sc_transaction_example_collection_size", "sc_transaction_example_collection_size", [ :pointer ], :int)
|
105
|
+
|
106
|
+
attach_function("sc_transaction_example_handle", "sc_transaction_example_handle", [ :pointer, :int ], :pointer)
|
107
|
+
attach_function("sc_transaction_example_name", "sc_transaction_example_name", [ :pointer ], :string)
|
108
|
+
attach_function("sc_transaction_example_description", "sc_transaction_example_description", [ :pointer ], :string)
|
109
|
+
|
110
|
+
attach_function("sc_result_free", "sc_result_free", [ :pointer ], :void)
|
111
|
+
|
112
|
+
attach_function("sc_location_handler", "sc_location_handler", [ :pointer ], :pointer)
|
113
|
+
attach_function("sc_location_size", "sc_location_size", [ :pointer ], :int)
|
114
|
+
attach_function("sc_location_length", "sc_location_length", [ :pointer, :int ], :int)
|
115
|
+
attach_function("sc_location_location", "sc_location_location", [ :pointer, :int ], :int)
|
116
|
+
|
117
|
+
attach_function("sc_error_handler", "sc_error_handler", [ :pointer ], :pointer)
|
118
|
+
attach_function("sc_error_message", "sc_error_message", [ :pointer ], :string)
|
119
|
+
attach_function("sc_error_code", "sc_error_code", [ :pointer ], :int)
|
120
|
+
attach_function("sc_error_ok", "sc_error_ok", [ :pointer ], :int)
|
121
|
+
|
122
|
+
attach_function("sc_warnings_handler", "sc_warnings_handler", [ :pointer ], :pointer)
|
123
|
+
attach_function("sc_warnings_size", "sc_warnings_size", [ :pointer ], :int)
|
124
|
+
attach_function("sc_warning_handler", "sc_warning_handler", [ :pointer, :int ], :pointer)
|
125
|
+
attach_function("sc_warning_message", "sc_warning_message", [ :pointer ], :string)
|
126
|
+
attach_function("sc_warning_code", "sc_warning_code", [ :pointer], :int)
|
127
|
+
attach_function("sc_warning_ok", "sc_warning_ok", [ :pointer ], :int)
|
128
|
+
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,365 @@
|
|
1
|
+
require "redsnow/object"
|
2
|
+
|
3
|
+
# The classes in this module should be 1:1 with the Snow Crash AST
|
4
|
+
# counterparts (https://github.com/apiaryio/snowcrash/blob/master/src/Blueprint.h).
|
5
|
+
module RedSnow
|
6
|
+
|
7
|
+
# Blueprint AST node
|
8
|
+
# Base class for API Blueprint AST nodes
|
9
|
+
#
|
10
|
+
# @abstract
|
11
|
+
class BlueprintNode
|
12
|
+
end
|
13
|
+
|
14
|
+
# Blueprint AST node with name and description associated
|
15
|
+
#
|
16
|
+
# @attr name [String] name of the node
|
17
|
+
# @attr description [String] description of the node
|
18
|
+
#
|
19
|
+
# @abstract
|
20
|
+
class NamedBlueprintNode < BlueprintNode
|
21
|
+
|
22
|
+
attr_accessor :name
|
23
|
+
attr_accessor :description
|
24
|
+
|
25
|
+
# Ensure the input string buffer ends with two newlines.
|
26
|
+
#
|
27
|
+
# @param buffer [String] a buffer to check
|
28
|
+
# If the buffer does not ends with two newlines the newlines are added.
|
29
|
+
def ensure_description_newlines(buffer)
|
30
|
+
return if description.empty?
|
31
|
+
|
32
|
+
if description[-1, 1] != "\n"
|
33
|
+
buffer << "\n\n"
|
34
|
+
elsif description.length > 1 && description[-2, 1] != "\n"
|
35
|
+
buffer << "\n"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Blueprint AST node for key-value collections
|
41
|
+
#
|
42
|
+
# @abstract
|
43
|
+
# @attr collection [Array<Hash>] array of key value hashes
|
44
|
+
class KeyValueCollection < BlueprintNode
|
45
|
+
|
46
|
+
attr_accessor :collection
|
47
|
+
|
48
|
+
# Filter collection keys
|
49
|
+
#
|
50
|
+
# @return [Array<Hash>] collection without ignored keys
|
51
|
+
def filter_collection(ignore_keys)
|
52
|
+
return @collection if ignore_keys.blank?
|
53
|
+
@collection.select { |kv_item| !ignore_keys.include?(kv_item.keys.first) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Metadata collection Blueprint AST node
|
58
|
+
# represents 'metadata section'
|
59
|
+
class Metadata < KeyValueCollection
|
60
|
+
# Constructor
|
61
|
+
# @param sc_metadata_collection_handle [FFI::Pointer]
|
62
|
+
def initialize(sc_metadata_collection_handle)
|
63
|
+
sc_metadata_collection_size = RedSnow::Binding.sc_metadata_collection_size(sc_metadata_collection_handle)
|
64
|
+
if sc_metadata_collection_size > 0
|
65
|
+
metadata_size = sc_metadata_collection_size - 1
|
66
|
+
@collection = Array.new
|
67
|
+
for index in 0..metadata_size do
|
68
|
+
sc_metadata_handle = RedSnow::Binding.sc_metadata_handle(sc_metadata_collection_handle, index)
|
69
|
+
@collection << Hash[:name => RedSnow::Binding.sc_metadata_key(sc_metadata_handle), :value => RedSnow::Binding.sc_metadata_value(sc_metadata_handle)]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Headers collection Blueprint AST node
|
76
|
+
# represents 'headers section'
|
77
|
+
class Headers < KeyValueCollection
|
78
|
+
|
79
|
+
# HTTP 'Content-Type' header
|
80
|
+
CONTENT_TYPE_HEADER_KEY = :'Content-Type'
|
81
|
+
|
82
|
+
|
83
|
+
# @return [String] the value of 'Content-type' header if present or nil
|
84
|
+
def content_type
|
85
|
+
content_type_header = @collection.detect { |header| header.has_key?(CONTENT_TYPE_HEADER_KEY) }
|
86
|
+
return (content_type_header.nil?) ? nil : content_type_header[CONTENT_TYPE_HEADER_KEY]
|
87
|
+
end
|
88
|
+
# @param sc_header_collection_handle_payload [FFI::Pointer]
|
89
|
+
def initialize(sc_header_collection_handle_payload)
|
90
|
+
sc_header_collection_size = RedSnow::Binding.sc_header_collection_size(sc_header_collection_handle_payload)
|
91
|
+
if sc_header_collection_size > 0
|
92
|
+
headers_size = sc_header_collection_size - 1
|
93
|
+
@collection = Array.new
|
94
|
+
for index in 0..headers_size do
|
95
|
+
sc_header_handle = RedSnow::Binding.sc_header_handle(sc_header_collection_handle_payload, index)
|
96
|
+
@collection << Hash[:name => RedSnow::Binding.sc_header_key(sc_header_handle), :value => RedSnow::Binding.sc_header_value(sc_header_handle)]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
# URI parameter Blueprint AST node
|
104
|
+
# represents one 'parameters section' parameter
|
105
|
+
#
|
106
|
+
# @attr type [String] an arbitrary type of the parameter or nil
|
107
|
+
# @attr use [Symbol] parameter necessity flag, `:required` or `:optional`
|
108
|
+
# @attr default_value [String] default value of the parameter or nil
|
109
|
+
# This is a value used when the parameter is ommited in the request.
|
110
|
+
# @attr example_value [String] example value of the parameter or nil
|
111
|
+
# @attr values [Array<String>] an enumeration of possible parameter values
|
112
|
+
class Parameter < NamedBlueprintNode
|
113
|
+
|
114
|
+
attr_accessor :type
|
115
|
+
attr_accessor :use
|
116
|
+
attr_accessor :default_value
|
117
|
+
attr_accessor :example_value
|
118
|
+
attr_accessor :values
|
119
|
+
# @param sc_parameter_handle [FFI::Pointer]
|
120
|
+
def initialize(sc_parameter_handle)
|
121
|
+
@name = RedSnow::Binding.sc_parameter_name(sc_parameter_handle)
|
122
|
+
@description = RedSnow::Binding.sc_parameter_description(sc_parameter_handle)
|
123
|
+
@type = RedSnow::Binding.sc_parameter_type(sc_parameter_handle)
|
124
|
+
@use = RedSnow::Binding.sc_parameter_parameter_use(sc_parameter_handle)
|
125
|
+
@default_value = RedSnow::Binding.sc_parameter_default_value(sc_parameter_handle)
|
126
|
+
@example_value = RedSnow::Binding.sc_parameter_example_value(sc_parameter_handle)
|
127
|
+
@values = Array.new
|
128
|
+
sc_value_collection_handle = RedSnow::Binding.sc_value_collection_handle(sc_parameter_handle)
|
129
|
+
sc_value_collection_size = RedSnow::Binding.sc_value_collection_size(sc_value_collection_handle)
|
130
|
+
if sc_value_collection_size > 0
|
131
|
+
values_size = sc_value_collection_size - 1
|
132
|
+
for valueIndex in 0..values_size do
|
133
|
+
sc_value_handle = RedSnow::Binding.sc_value_handle(sc_value_collection_handle, valueIndex)
|
134
|
+
value = RedSnow::Binding.sc_value_string(sc_value_handle)
|
135
|
+
@values << value
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
# Collection of URI parameters Blueprint AST node
|
143
|
+
# represents 'parameters section'
|
144
|
+
#
|
145
|
+
# @attr collection [Array<Parameter>] an array of URI parameters
|
146
|
+
class Parameters < BlueprintNode
|
147
|
+
|
148
|
+
attr_accessor :collection
|
149
|
+
# @param sc_parameter_collection_handle [FFI::Pointer]
|
150
|
+
def initialize(sc_parameter_collection_handle)
|
151
|
+
sc_parameter_collection_size = RedSnow::Binding.sc_parameter_collection_size(sc_parameter_collection_handle)
|
152
|
+
@collection = Array.new
|
153
|
+
if sc_parameter_collection_size > 0
|
154
|
+
parameters_size = sc_parameter_collection_size - 1
|
155
|
+
for index in 0..parameters_size do
|
156
|
+
sc_parameter_handle = RedSnow::Binding.sc_parameter_handle(sc_parameter_collection_handle, index)
|
157
|
+
parameter = Parameter.new(sc_parameter_handle)
|
158
|
+
@collection << parameter
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
# HTTP message payload Blueprint AST node
|
166
|
+
# base class for 'payload sections'
|
167
|
+
#
|
168
|
+
# @abstract
|
169
|
+
# @attr parameters [Array] ignored
|
170
|
+
# @attr headers [Array<Headers>] array of HTTP header fields of the message or nil
|
171
|
+
# @attr body [String] HTTP-message body or nil
|
172
|
+
# @attr schema [String] HTTP-message body validation schema or nil
|
173
|
+
class Payload < NamedBlueprintNode
|
174
|
+
|
175
|
+
attr_accessor :parameters
|
176
|
+
attr_accessor :headers
|
177
|
+
attr_accessor :body
|
178
|
+
attr_accessor :schema
|
179
|
+
# @param sc_payload_handle_resource [FFI::Pointer]
|
180
|
+
def initialize(sc_payload_handle_resource)
|
181
|
+
@name = RedSnow::Binding.sc_payload_name(sc_payload_handle_resource)
|
182
|
+
@description = RedSnow::Binding.sc_payload_description(sc_payload_handle_resource)
|
183
|
+
@body = RedSnow::Binding.sc_payload_body(sc_payload_handle_resource)
|
184
|
+
@schema = RedSnow::Binding.sc_payload_schema(sc_payload_handle_resource)
|
185
|
+
|
186
|
+
sc_header_collection_handle_payload = RedSnow::Binding.sc_header_collection_handle_payload(sc_payload_handle_resource)
|
187
|
+
@headers = Headers.new(sc_header_collection_handle_payload)
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
# Transaction example Blueprint AST node
|
193
|
+
#
|
194
|
+
# @attr requests [Array<Request>] example request payloads
|
195
|
+
# @attr response [Array<Response>] example response payloads
|
196
|
+
class TransactionExample < NamedBlueprintNode
|
197
|
+
|
198
|
+
attr_accessor :requests
|
199
|
+
attr_accessor :responses
|
200
|
+
# @param sc_transaction_example_handle [FFI::Pointer]
|
201
|
+
def initialize(sc_transaction_example_handle)
|
202
|
+
@name = RedSnow::Binding.sc_transaction_example_name(sc_transaction_example_handle)
|
203
|
+
@description = RedSnow::Binding.sc_transaction_example_description(sc_transaction_example_handle)
|
204
|
+
# BP Resource Actions Examples Requests
|
205
|
+
@requests = Array.new
|
206
|
+
sc_payload_collection_handle_requests = RedSnow::Binding.sc_payload_collection_handle_requests(sc_transaction_example_handle)
|
207
|
+
sc_payload_collection_size_requests = RedSnow::Binding.sc_payload_collection_size(sc_payload_collection_handle_requests)
|
208
|
+
if sc_payload_collection_size_requests > 0
|
209
|
+
requests_size = sc_payload_collection_size_requests - 1
|
210
|
+
for index in 0..requests_size do
|
211
|
+
request = Payload.new(RedSnow::Binding.sc_payload_handle(sc_payload_collection_handle_requests, index))
|
212
|
+
@requests << request
|
213
|
+
end
|
214
|
+
end
|
215
|
+
# BP Resource Actions Examples Responses
|
216
|
+
@responses = Array.new
|
217
|
+
sc_payload_collection_handle_responses = RedSnow::Binding.sc_payload_collection_handle_responses(sc_transaction_example_handle)
|
218
|
+
sc_payload_collection_size_responses = RedSnow::Binding.sc_payload_collection_size(sc_payload_collection_handle_responses)
|
219
|
+
if sc_payload_collection_size_responses > 0
|
220
|
+
responses_size = sc_payload_collection_size_responses - 1
|
221
|
+
for index in 0..responses_size do
|
222
|
+
response = Payload.new(RedSnow::Binding.sc_payload_handle(sc_payload_collection_handle_responses, index))
|
223
|
+
@responses << response
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
# Action Blueprint AST node
|
232
|
+
# represetns 'action sction'
|
233
|
+
#
|
234
|
+
# @attr method [String] HTTP request method or nil
|
235
|
+
# @attr parameters [Parameters] action-specific URI parameters or nil
|
236
|
+
# @attr examples [Array<TransactionExample>] action transaction examples
|
237
|
+
class Action < NamedBlueprintNode
|
238
|
+
|
239
|
+
attr_accessor :method
|
240
|
+
attr_accessor :parameters
|
241
|
+
attr_accessor :examples
|
242
|
+
# @param sc_action_handle [FFI::Pointer]
|
243
|
+
def initialize(sc_action_handle)
|
244
|
+
@name = RedSnow::Binding.sc_action_name(sc_action_handle)
|
245
|
+
@description = RedSnow::Binding.sc_action_description(sc_action_handle)
|
246
|
+
|
247
|
+
@method = RedSnow::Binding.sc_action_httpmethod(sc_action_handle)
|
248
|
+
|
249
|
+
@parameters = Parameters.new(RedSnow::Binding.sc_parameter_collection_handle_action(sc_action_handle))
|
250
|
+
|
251
|
+
@examples = Array.new
|
252
|
+
sc_transaction_example_collection_handle = RedSnow::Binding.sc_transaction_example_collection_handle(sc_action_handle)
|
253
|
+
sc_transaction_example_collection_size = RedSnow::Binding.sc_transaction_example_collection_size(sc_transaction_example_collection_handle)
|
254
|
+
if sc_transaction_example_collection_size > 0
|
255
|
+
examples_size = sc_transaction_example_collection_size - 1
|
256
|
+
for index in 0..examples_size do
|
257
|
+
example = TransactionExample.new(RedSnow::Binding.sc_transaction_example_handle(sc_transaction_example_collection_handle, index))
|
258
|
+
@examples << example
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
# Resource Blueprint AST node
|
266
|
+
# represents 'resource section'
|
267
|
+
#
|
268
|
+
# @attr uri_template [String] RFC 6570 URI template
|
269
|
+
# @attr model [Model] model payload for the resource or nil
|
270
|
+
# @attr parameters [Parameters] action-specific URI parameters or nil
|
271
|
+
# @attr actions [Array<Action>] array of resource actions or nil
|
272
|
+
class Resource < NamedBlueprintNode
|
273
|
+
|
274
|
+
attr_accessor :uri_template
|
275
|
+
attr_accessor :model
|
276
|
+
attr_accessor :parameters
|
277
|
+
attr_accessor :actions
|
278
|
+
# @param sc_resource_handle [FFI::Pointer]
|
279
|
+
def initialize(sc_resource_handle)
|
280
|
+
@name = RedSnow::Binding.sc_resource_name(sc_resource_handle)
|
281
|
+
@description = RedSnow::Binding.sc_resource_description(sc_resource_handle)
|
282
|
+
@uri_template = RedSnow::Binding.sc_resource_uritemplate(sc_resource_handle)
|
283
|
+
|
284
|
+
sc_payload_handle_resource = RedSnow::Binding.sc_payload_handle_resource(sc_resource_handle)
|
285
|
+
@model = Payload.new(sc_payload_handle_resource)
|
286
|
+
|
287
|
+
@actions = Array.new
|
288
|
+
sc_action_collection_handle = RedSnow::Binding.sc_action_collection_handle(sc_resource_handle)
|
289
|
+
sc_action_collection_size = RedSnow::Binding.sc_action_collection_size(sc_action_collection_handle)
|
290
|
+
if sc_action_collection_size > 0
|
291
|
+
action_size = sc_action_collection_size - 1
|
292
|
+
for index in 0..action_size do
|
293
|
+
@actions << Action.new(RedSnow::Binding.sc_action_handle(sc_action_collection_handle, index))
|
294
|
+
end
|
295
|
+
end
|
296
|
+
@parameters = Parameters.new(RedSnow::Binding.sc_parameter_collection_handle_resource(sc_resource_handle))
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
# Resource group Blueprint AST node
|
302
|
+
# represents 'resource group section'
|
303
|
+
#
|
304
|
+
# @attr resources [Array<Resource>] array of resources in the group
|
305
|
+
class ResourceGroup < NamedBlueprintNode
|
306
|
+
|
307
|
+
attr_accessor :resources
|
308
|
+
# @param sc_resource_groups_handle [FFI::Pointer]
|
309
|
+
def initialize(sc_resource_groups_handle)
|
310
|
+
@name = RedSnow::Binding.sc_resource_groups_name(sc_resource_groups_handle)
|
311
|
+
@description = RedSnow::Binding.sc_resource_groups_description(sc_resource_groups_handle)
|
312
|
+
|
313
|
+
@resources = Array.new
|
314
|
+
sc_resource_collection_handle = RedSnow::Binding.sc_resource_collection_handle(sc_resource_groups_handle)
|
315
|
+
sc_resource_collection_size = RedSnow::Binding.sc_resource_collection_size(sc_resource_collection_handle)
|
316
|
+
if sc_resource_collection_size > 0
|
317
|
+
resource_size = sc_resource_collection_size - 1
|
318
|
+
for index in 0..resource_size do
|
319
|
+
sc_resource_handle = RedSnow::Binding.sc_resource_handle(sc_resource_collection_handle, index)
|
320
|
+
res = Resource.new(sc_resource_handle)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
@resources << res
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
# Top-level Blueprint AST node
|
330
|
+
# represents 'blueprint section'
|
331
|
+
#
|
332
|
+
# @attr metadata [Metadata] tool-specific metadata collection or nil
|
333
|
+
# @attr resource_groups [Array<ResourceGroup>] array of blueprint resource groups
|
334
|
+
class Blueprint < NamedBlueprintNode
|
335
|
+
|
336
|
+
attr_accessor :metadata
|
337
|
+
attr_accessor :resource_groups
|
338
|
+
# Version key
|
339
|
+
VERSION_KEY = :_version
|
340
|
+
# Supported version of Api Blueprint
|
341
|
+
SUPPORTED_VERSIONS = ["2.0"]
|
342
|
+
# @param handle [FFI:Pointer]
|
343
|
+
def initialize(handle)
|
344
|
+
# BP name, desc
|
345
|
+
@name = RedSnow::Binding.sc_blueprint_name(handle)
|
346
|
+
@description = RedSnow::Binding.sc_blueprint_description(handle)
|
347
|
+
|
348
|
+
# BP metadata
|
349
|
+
sc_metadata_collection_handle = RedSnow::Binding.sc_metadata_collection_handle(handle)
|
350
|
+
@metadata = Metadata.new(sc_metadata_collection_handle)
|
351
|
+
|
352
|
+
# BP Resource Groups
|
353
|
+
sc_resource_groups_collection_handle = RedSnow::Binding.sc_resource_groups_collection_handle(handle)
|
354
|
+
sc_resource_groups_collection_size = RedSnow::Binding.sc_resource_groups_collection_size(sc_resource_groups_collection_handle)
|
355
|
+
@resource_groups = Array.new
|
356
|
+
if sc_resource_groups_collection_size > 0
|
357
|
+
group_size = sc_resource_groups_collection_size - 1
|
358
|
+
for index in 0..group_size do
|
359
|
+
sc_resource_groups_handle = RedSnow::Binding.sc_resource_groups_handle(sc_resource_groups_collection_handle, index)
|
360
|
+
@resource_groups << ResourceGroup.new(sc_resource_groups_handle)
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|