class Apitools::Middleware::Spec
Constants
- MANIFEST_FILE
- SPEC_ATTRIBUTES
Attributes
repo[R]
Public Class Methods
new(repo, path)
click to toggle source
# File lib/apitools/middleware/spec.rb, line 14 def initialize(repo, path) @repo = repo @path, @manifest_file = extract_path_and_manifest(path) end
Public Instance Methods
code()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 27 def code @code ||= load_code end
endpoint()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 39 def endpoint Array(endpoints).first end
extract_path_and_manifest(path)
click to toggle source
# File lib/apitools/middleware/spec.rb, line 79 def extract_path_and_manifest(path) pathname = Pathname(path) if pathname.extname.empty? # no manifest at the end [pathname, MANIFEST_FILE] else [pathname.dirname, pathname.basename] end end
files()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 43 def files Array(manifest.files) end
manifest()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 23 def manifest @manifest ||= Manifest.parse(load_manifest) end
manifest=(json)
click to toggle source
# File lib/apitools/middleware/spec.rb, line 19 def manifest=(json) @manifest = Manifest.parse(json) end
manifest_file()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 35 def manifest_file @manifest_file.to_s end
method_missing(method, *)
click to toggle source
# File lib/apitools/middleware/spec.rb, line 47 def method_missing(method, *) hash = manifest.to_h if hash && hash.has_key?(method) hash.fetch(method) end end
path()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 31 def path @path.to_s end
respond_to_missing?(method, *)
click to toggle source
Calls superclass method
# File lib/apitools/middleware/spec.rb, line 55 def respond_to_missing?(method, *) hash = manifest.to_h hash && hash.has_key?(method) || super end
to_h()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 60 def to_h SPEC_ATTRIBUTES.map{|attr| [attr, public_send(attr)] }.to_h end
valid?()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 70 def valid? required_attributes = [name, path, author, endpoint, version, description] return unless required_attributes.all? lua_files = Array(files).map { |file| content(file) } return if lua_files.empty? lua_files.none?{ |file| !file || file.nil? || file.empty? } end
version()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 64 def version Semantic::Version.new(manifest.version) rescue ArgumentError false end
Protected Instance Methods
content(path)
click to toggle source
# File lib/apitools/middleware/spec.rb, line 91 def content(path) @repo.content @path.join(path) end
load_code()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 99 def load_code content files.first end
load_manifest()
click to toggle source
# File lib/apitools/middleware/spec.rb, line 95 def load_manifest content @manifest_file end