Module: Dphil

Defined in:
lib/dphil.rb,
lib/dphil/cli.rb,
lib/dphil/paup.rb,
lib/dphil/tree.rb,
lib/dphil/cache.rb,
lib/dphil/lemma.rb,
lib/dphil/verse.rb,
lib/dphil/logger.rb,
lib/dphil/newick.rb,
lib/dphil/tei_xml.rb,
lib/dphil/version.rb,
lib/dphil/character.rb,
lib/dphil/constants.rb,
lib/dphil/converter.rb,
lib/dphil/ld_output.rb,
lib/dphil/syllables.rb,
lib/dphil/tree_node.rb,
lib/dphil/lemma_list.rb,
lib/dphil/change_list.rb,
lib/dphil/ld_data_set.rb,
lib/dphil/refinements.rb,
lib/dphil/log_formatter.rb,
lib/dphil/metrical_data.rb,
lib/dphil/script_string.rb,
lib/dphil/transliterate.rb,
lib/dphil/verse_analysis.rb,
lib/dphil/character_matrix.rb,
lib/dphil/converters/csv2nex.rb,
lib/dphil/syllables/syllable.rb,
lib/dphil/verse_analysis_new.rb,
lib/dphil/refinements/natural_sort.rb

Overview

Namespace module definition

Defined Under Namespace

Modules: CLI, Constants, Converter, LDOutput, MetricalData, NewickTree, PAUP, Refinements, Transliterate, VerseAnalysis Classes: ChangeList, Character, CharacterMatrix, Csv2NexConverter, LDDataSet, Lemma, LemmaList, LogFormatter, ScriptString, Syllables, TeiXML, Tree, TreeNode, Verse

Constant Summary collapse

GEM_ROOT =
Pathname.new(File.join(__dir__, "..", "..")).realpath.freeze
VERSION =
"0.1.4"
VERSION_CHECKSUM =
begin
  gem_files = (
    Pathname.glob(File.join(GEM_ROOT, "{Gemfile,*.gemspec,Rakefile}")) +
    Pathname.glob(File.join(GEM_ROOT, "{exe,lib,vendor}", "**", "*"))
  ).select { |file| File.file?(file) }

  checksum = gem_files.reduce(Zlib.crc32) do |memo, file|
    file_data = File.read(file)
                    .prepend("#{file.relative_path_from(GEM_ROOT)}\n---\n")
    Zlib.crc32(file_data, memo)
  end

  byte_str = 3.downto(0).each_with_object(String.new(capacity: 4)) do |byte, str|
    str << ((checksum >> (byte * 8)) & 0xFF).chr
  end
  [byte_str].pack("m0").gsub(/[\=\+]+/, "").freeze
end
VERSION_FULL =
"#{VERSION}-#{VERSION_CHECKSUM}"

Class Method Summary collapse

Class Method Details

.cache(key, params = nil) ⇒ Object



9
10
11
12
13
14
# File 'lib/dphil/cache.rb', line 9

def cache(key, params = nil)
  @cache ||= defined?(::Rails.cache) ? ::Rails.cache : ActiveSupport::Cache::MemoryStore.new(size: 16_384)
  full_key = String.new("Dphil-#{Dphil::VERSION}:cache:#{key}")
  full_key << ":#{Digest::SHA1.base64digest(params.to_s)}" unless params.nil?
  block_given? ? @cache.fetch(full_key, &Proc.new) : @cache.fetch(full_key)
end

.loggerObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dphil/logger.rb', line 11

def logger
  @logger ||= begin
    if defined?(::Rails) && defined?(::Rails.logger)
      ::Rails.logger
    else
      file_logger = ActiveSupport::Logger.new(File.join(GEM_ROOT, "dphil.log"))
      file_logger.formatter = LogFormatter.new
      if Constants::DEBUG
        logger = ActiveSupport::Logger.new(STDERR)
        logger.formatter = file_logger.formatter
        file_logger.extend(ActiveSupport::Logger.broadcast(logger))
      end
      file_logger
    end
  end
end