Sha256: a8f53f52c8b1c775b106babe915085fcee8661f3dbf8378fe750e174ec81e042
Contents?: true
Size: 925 Bytes
Versions: 13
Compression:
Stored size: 925 Bytes
Contents
# frozen_string_literal: true require "json" require "fileutils" module Spout module Models # Base class for spout variables, forms, and domains that are read from JSON # files class Record class << self # Only returns records with zero json errors, nil otherwise def find_by_id(id) file_name = Dir.glob(expected_path(id), File::FNM_CASEFOLD).first variable = new(file_name, dictionary_root) (variable.errors.size > 0 ? nil : variable) end private def record_folder "#{name.split('::').last.to_s.downcase}s" end def expected_filename(id) "#{id.to_s.downcase}.json" end def expected_path(id) File.join(dictionary_root, record_folder, "**", expected_filename(id)) end def dictionary_root FileUtils.pwd end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems