Class: Apitools::Middleware::Spec
- Inherits:
-
Object
- Object
- Apitools::Middleware::Spec
- Extended by:
- Forwardable
- Defined in:
- lib/apitools/middleware/spec.rb
Constant Summary collapse
- MANIFEST_FILE =
should be apitools.json
'apitools.json'
Instance Attribute Summary collapse
-
#manifest_path ⇒ Object
readonly
Returns the value of attribute manifest_path.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #code ⇒ Object
- #endpoint ⇒ Object
- #files ⇒ Object
-
#initialize(repo, path) ⇒ Spec
constructor
A new instance of Spec.
- #manifest ⇒ Object
- #manifest=(json) ⇒ Object
- #valid? ⇒ Boolean
- #version ⇒ Object
Constructor Details
#initialize(repo, path) ⇒ Spec
Returns a new instance of Spec.
16 17 18 19 20 21 |
# File 'lib/apitools/middleware/spec.rb', line 16 def initialize(repo, path) @repo = repo pathname = Pathname(path) @path = pathname.dirname @manifest_path = pathname.basename || MANIFEST_FILE end |
Instance Attribute Details
#manifest_path ⇒ Object (readonly)
Returns the value of attribute manifest_path.
11 12 13 |
# File 'lib/apitools/middleware/spec.rb', line 11 def manifest_path @manifest_path end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/apitools/middleware/spec.rb', line 11 def path @path end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
11 12 13 |
# File 'lib/apitools/middleware/spec.rb', line 11 def repo @repo end |
Instance Method Details
#code ⇒ Object
31 32 33 |
# File 'lib/apitools/middleware/spec.rb', line 31 def code @code ||= load_code end |
#endpoint ⇒ Object
35 36 37 |
# File 'lib/apitools/middleware/spec.rb', line 35 def endpoint Array(endpoints).first end |
#files ⇒ Object
39 40 41 |
# File 'lib/apitools/middleware/spec.rb', line 39 def files Array(manifest.files) end |
#manifest ⇒ Object
27 28 29 |
# File 'lib/apitools/middleware/spec.rb', line 27 def manifest @manifest ||= Manifest.parse(load_manifest) end |
#manifest=(json) ⇒ Object
23 24 25 |
# File 'lib/apitools/middleware/spec.rb', line 23 def manifest=(json) @manifest = Manifest.parse(json) end |
#valid? ⇒ Boolean
49 50 51 52 53 54 55 |
# File 'lib/apitools/middleware/spec.rb', line 49 def valid? required_attributes = [name, path, , endpoint, version, description] return unless required_attributes.all? lua_files = Array(files).map { |file| content(file) } lua_files.none?{ |file| !file || file.nil? || file.empty? } end |
#version ⇒ Object
43 44 45 46 47 |
# File 'lib/apitools/middleware/spec.rb', line 43 def version Semantic::Version.new(manifest.version) rescue ArgumentError false end |