class Shaf::Yard::Parser

Attributes

name[R]

Public Class Methods

call(name: '') click to toggle source
# File lib/shaf/yard/parser.rb, line 6
def self.call(name: '')
  new(name).parse!
end
new(name) click to toggle source
# File lib/shaf/yard/parser.rb, line 10
def initialize(name)
  @name = name.downcase
end

Public Instance Methods

parse!() click to toggle source
# File lib/shaf/yard/parser.rb, line 14
def parse!
  verify_exists! unless name.empty?
  ::YARD.parse pattern
end

Private Instance Methods

base_dir() click to toggle source
# File lib/shaf/yard/parser.rb, line 46
def base_dir
  File.join(Shaf::Settings.app_dir || 'api', 'serializers')
end
file_path() click to toggle source
# File lib/shaf/yard/parser.rb, line 42
def file_path
  @file_path ||= lookup_path
end
lookup_path() click to toggle source
# File lib/shaf/yard/parser.rb, line 50
def lookup_path
  return if name.empty?

  path = File.join(base_dir, name)
  return path if File.exist? path

  with_suffix = [path, suffix].join
  return with_suffix if File.exist? with_suffix

  with_extension = [path, '.rb'].join
  with_extension if File.exist? with_extension
end
pattern() click to toggle source
# File lib/shaf/yard/parser.rb, line 23
def pattern
  return file_path if file_path

  base = ['*', suffix].join
  File.join(base_dir, '**', base)
end
suffix() click to toggle source
# File lib/shaf/yard/parser.rb, line 30
def suffix
  '_serializer.rb'
end
verify_exists!() click to toggle source
# File lib/shaf/yard/parser.rb, line 34
      def verify_exists!
        file_path or raise <<~ERR
          Could not find a matching serializer for #{name}.
          Looked in: #{base_dir}
          Using suffix: #{suffix}
        ERR
      end