class Idcf::JsonHyperSchema::Analyst
json-hyper-schema analyst
Attributes
load_schema[R]
process_version[R]
schema[R]
Public Instance Methods
expand(schema, options = {})
click to toggle source
json file laod
@param schema [Hash] @param options [Hash] @return [Expand::Base] @raise
# File lib/idcf/json_hyper_schema/analyst.rb, line 41 def expand(schema, options = {}) return schema unless schema.class == Hash @process_version = schema_version(schema) # MEMO: # Ruby2.7系では以下のような警告がでる # # Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call # # Ruby2.7系以上だけをサポートの対象とするなら場合分ける必要ないがそうではないので場合分けをしている。 if RUBY_VERSION >= '2.7' result = expand_class.new(**options) else result = expand_class.new(options) end result.do!(schema) result end
json_schema_init()
click to toggle source
# File lib/idcf/json_hyper_schema/analyst.rb, line 9 def json_schema_init configuration = JsonSchema.configuration Idcf::JsonHyperSchema::Validation.validations.each do |key, val| configuration.register_format(key, val) end self end
links()
click to toggle source
links
@return Expands::LinkInfoBase
# File lib/idcf/json_hyper_schema/analyst.rb, line 62 def links json_schema_init p_schema = JsonSchema.parse!(@load_schema) @process_version = schema_version(p_schema) p_schema.expand_references! find_links(p_schema) end
load(path, options = {})
click to toggle source
json file laod
@param path [String] @param options [Hash] @return [Hash] @raise
# File lib/idcf/json_hyper_schema/analyst.rb, line 23 def load(path, options = {}) @schema ||= {} unless @schema[path].nil? @load_schema = @schema[path] return self end j = JSON.parse(File.read(path)) @load_schema = expand(j, options).schema @schema[path] = @load_schema self end
schema_links(schema, options = {})
click to toggle source
schema links
@param schema [Hash] @param options [Hash] @return Expands::LinkInfoBase
# File lib/idcf/json_hyper_schema/analyst.rb, line 75 def schema_links(schema, options = {}) ex_schema = expand(schema, options) json_schema_init p_schema = JsonSchema.parse!(ex_schema.schema) t_v = @process_version p_schema.expand_references! result = find_links(p_schema) @process_version = t_v result end
Protected Instance Methods
base_module()
click to toggle source
base module namespace
@return [String]
# File lib/idcf/json_hyper_schema/analyst.rb, line 92 def base_module list = self.class.to_s.underscore.split('/') list.pop list.join('/') end
expand_class()
click to toggle source
expand class
@return [Class]
# File lib/idcf/json_hyper_schema/analyst.rb, line 101 def expand_class path = "#{base_module}/expands/#{@process_version}" require path path.classify.constantize end
find_links(schema)
click to toggle source
find links
@param schema [JsonSchema::Schema] @return [Array] @raise
# File lib/idcf/json_hyper_schema/analyst.rb, line 112 def find_links(schema) [].tap do |result| l_class = link_class schema.links.each do |link| link_obj = l_class.new(link) result << link_obj end schema.properties.each_value do |sub| result.concat(find_links(sub)) end end end
link_class()
click to toggle source
link class
@return [Idcf::JsonHyperSchema::Expands::LinkInfoBase] @raise
# File lib/idcf/json_hyper_schema/analyst.rb, line 130 def link_class path = "#{base_module}/expands/link_info_#{@process_version}" require path path.classify.constantize end
schema_version(schema)
click to toggle source
schema version
@param schema [Hash] @return [String] @raise
# File lib/idcf/json_hyper_schema/analyst.rb, line 141 def schema_version(schema) v_list = schema_version_list result = v_list.last check = schema.is_a?(JsonSchema::Schema) ? schema.data : schema unless check['$schema'].nil? || check['$schema'].empty? result = schema_version_str(check['$schema']) end raise 'The undefined version.' if v_list.index(result).nil? result end
schema_version_list()
click to toggle source
schema version list support schema version list
@return array
# File lib/idcf/json_hyper_schema/analyst.rb, line 157 def schema_version_list result = [] Dir.glob("#{File.dirname(__FILE__)}/expands/v*.rb") do |f| result << File.basename(f, '.rb') end result.sort end
schema_version_str(schema)
click to toggle source
schema version str
@param schema [String] $schema @return [String]
# File lib/idcf/json_hyper_schema/analyst.rb, line 169 def schema_version_str(schema) schema =~ /draft[^\d]{1,2}(\d+)/ mt = Regexp.last_match(1) return "v#{mt.to_i}" unless mt.nil? '' end