Class: Synvert::Snippet

Inherits:
Object
  • Object
show all
Defined in:
lib/synvert/snippet.rb

Overview

Manage synvert snippets.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snippets_path) ⇒ Snippet

Returns a new instance of Snippet.



14
15
16
# File 'lib/synvert/snippet.rb', line 14

def initialize(snippets_path)
  @snippets_path = snippets_path
end

Class Method Details

.fetch_core_versionObject



9
10
11
12
# File 'lib/synvert/snippet.rb', line 9

def self.fetch_core_version
  content = URI.open('https://rubygems.org/api/v1/versions/synvert-core.json').read
  JSON.parse(content).first['number']
end

Instance Method Details

#syncObject

synchronize snippets from github.



19
20
21
22
23
24
25
26
# File 'lib/synvert/snippet.rb', line 19

def sync
  if File.exist?(@snippets_path)
    FileUtils.cd @snippets_path
    Kernel.system('git pull --rebase')
  else
    Kernel.system("git clone https://github.com/xinminlabs/synvert-snippets.git #{@snippets_path}")
  end
end