Module: Wrapture
- Defined in:
- lib/wrapture.rb,
lib/wrapture/scope.rb,
lib/wrapture/errors.rb,
lib/wrapture/comment.rb,
lib/wrapture/version.rb,
lib/wrapture/constants.rb,
lib/wrapture/enum_spec.rb,
lib/wrapture/normalize.rb,
lib/wrapture/rule_spec.rb,
lib/wrapture/type_spec.rb,
lib/wrapture/class_spec.rb,
lib/wrapture/param_spec.rb,
lib/wrapture/action_spec.rb,
lib/wrapture/struct_spec.rb,
lib/wrapture/constant_spec.rb,
lib/wrapture/function_spec.rb,
lib/wrapture/template_spec.rb,
lib/wrapture/wrapped_function_spec.rb
Overview
– Copyright 2019-2020 Joel E. Anderson
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ++
Defined Under Namespace
Classes: ActionSpec, ClassSpec, Comment, ConstantSpec, EnumSpec, FunctionSpec, InvalidDoc, InvalidSpecKey, InvalidTemplateUsage, MissingSpecKey, NoNamespace, ParamSpec, RuleSpec, Scope, StructSpec, TemplateSpec, TypeSpec, UndefinableSpec, UnsupportedSpecVersion, WrappedFunctionSpec, WraptureError
Constant Summary collapse
- VERSION =
the current version of Wrapture
'0.5.0'- EQUIVALENT_STRUCT_KEYWORD =
A string denoting an equivalent struct type or value.
'equivalent-struct'- EQUIVALENT_POINTER_KEYWORD =
A string denoting a pointer to an equivalent struct type or value.
'equivalent-struct-pointer'- RETURN_VALUE_KEYWORD =
A string denoting the return value of a wrapped function call.
'return-value'- SELF_REFERENCE_KEYWORD =
A string denoting a reference to the object a method is called on.
'self-reference'- TEMPLATE_USE_KEYWORD =
A string denoting a reference to a template.
'use-template'- KEYWORDS =
A list of all keywords.
[EQUIVALENT_STRUCT_KEYWORD, EQUIVALENT_POINTER_KEYWORD, SELF_REFERENCE_KEYWORD, RETURN_VALUE_KEYWORD, TEMPLATE_USE_KEYWORD].freeze
Class Method Summary collapse
-
.normalize_boolean(spec, key) ⇒ Object
Normalizes a spec key to be boolean, raising an error if it is not.
-
.normalize_includes(includes) ⇒ Object
Normalizes an include list for an element.
-
.spec_version(spec) ⇒ Object
Returns the spec version for the provided spec.
-
.supports_version?(version) ⇒ Boolean
Returns true if the version of the spec is supported by this version of Wrapture.
Class Method Details
.normalize_boolean(spec, key) ⇒ Object
Normalizes a spec key to be boolean, raising an error if it is not. Keys that are not present are defaulted to false.
24 25 26 27 28 29 30 |
# File 'lib/wrapture/normalize.rb', line 24 def self.normalize_boolean(spec, key) is_boolean = [true, false].include?(spec[key]) error_msg = "'#{key}' key may only be true or false" raise(InvalidSpecKey, error_msg) unless !spec.key?(key) || is_boolean spec.key?(key) && spec[key] end |
.normalize_includes(includes) ⇒ Object
Normalizes an include list for an element. A single string will be converted into an array containing the single string, and a nil will be converted to an empty array.
35 36 37 38 39 40 41 42 43 |
# File 'lib/wrapture/normalize.rb', line 35 def self.normalize_includes(includes) if includes.nil? [] elsif includes.is_a? String [includes] else includes.uniq end end |
.spec_version(spec) ⇒ Object
Returns the spec version for the provided spec. If the version is not provided in the spec, the newest version that the spec is compliant with will be returned instead.
If this spec uses a version unsupported by this version of Wrapture or the spec is otherwise invalid, an exception is raised.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wrapture/normalize.rb', line 51 def self.spec_version(spec) if spec.key?('version') && !Wrapture.supports_version?(spec['version']) raise UnsupportedSpecVersion end if spec.key?('version') spec['version'] else Wrapture::VERSION end end |
.supports_version?(version) ⇒ Boolean
Returns true if the version of the spec is supported by this version of Wrapture. Otherwise returns false.
27 28 29 30 31 32 |
# File 'lib/wrapture/version.rb', line 27 def self.supports_version?(version) wrapture_version = Gem::Version.new(Wrapture::VERSION) spec_version = Gem::Version.new(version) spec_version <= wrapture_version end |