Class: Gitmoji::Regex::Reference

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/gitmoji/regex/reference.rb

Overview

Reference provides utility tools for maintaining and testing this gem

Constant Summary collapse

GITMOJI_REFERENCE =
"https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json"
GITMOJI_PATH =
"src/gitmojis.json"
LIB_SRC =
"lib/gitmoji/regex.rb"
TEMPLATE_SRC =
"src/regex.rb"

Instance Method Summary collapse

Instance Method Details

#cached_patternObject



26
27
28
# File 'lib/gitmoji/regex/reference.rb', line 26

def cached_pattern
  pattern(cached)
end

#compare_jsonObject



20
21
22
23
24
# File 'lib/gitmoji/regex/reference.rb', line 20

def compare_json
  return true if cached_pattern == fetched_pattern

  false
end

#compare_srcObject



34
35
36
37
38
# File 'lib/gitmoji/regex/reference.rb', line 34

def compare_src
  return true if current_src == next_src

  false
end

#current_srcObject



40
41
42
# File 'lib/gitmoji/regex/reference.rb', line 40

def current_src
  File.read(LIB_SRC)
end

#fetched_patternObject



30
31
32
# File 'lib/gitmoji/regex/reference.rb', line 30

def fetched_pattern
  pattern(fetch)
end

#next_srcObject



44
45
46
47
48
# File 'lib/gitmoji/regex/reference.rb', line 44

def next_src
  template_src = File.read(TEMPLATE_SRC)
  template_src = template_src.sub(/% gitmojiRegex %/, pattern(fetch).to_s)
  template_src.to_s
end

#to_a(body = nil) ⇒ Object



50
51
52
53
54
55
# File 'lib/gitmoji/regex/reference.rb', line 50

def to_a(body = nil)
  body ||= cached
  json = JSON.parse(body)
  gitmoji = json["gitmojis"]
  gitmoji.map { |g| g["emoji"] }
end

#write_jsonObject



57
58
59
60
61
62
# File 'lib/gitmoji/regex/reference.rb', line 57

def write_json
  file = File.write(GITMOJI_PATH, fetch)
  @cached = nil
  @cached_pattern = nil
  file
end

#write_srcObject



64
65
66
# File 'lib/gitmoji/regex/reference.rb', line 64

def write_src
  File.write(LIB_SRC, next_src)
end