This repository was archived by the owner on Oct 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThorfile
More file actions
51 lines (42 loc) · 1.27 KB
/
Thorfile
File metadata and controls
51 lines (42 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Seed < Thor
require 'rest_client'
require 'json'
attr_accessor :db
def initialize(*)
super
@db = JSON.parse( File.read '.couchapprc' )['env']['default']['db']
end
desc 'all', 'seed database with articles, screencasts, and scripts'
def all
articles && screencasts && scripts
end
desc 'articles', 'seed database with articles'
def articles
post('articles')
end
desc 'screencasts', 'seed database with screencasts'
def screencasts
post('screencasts')
end
desc 'scripts', 'seed database with scripts'
def scripts
post('scripts')
end
desc 'docify', 'converts vim scripts json data into a format acceptable to couchdb. See README for more info.'
method_option "--push",
:type => :boolean,
:aliases => "-p",
:banner => "Push docs to couchdb after docifying"
def docify(file = 'data/scripts.json')
puts "Docifying..."
system "sed -r -f data/scripts_to_doc.sed -i #{file}"
puts "DONE!"
post File.basename(file, File.extname(file)) if options['push'] || options['p']
end
private
def post(type)
docs = File.read "./data/#{type}.json"
puts "Pushing #{type}"
RestClient.post "#{@db}/_bulk_docs", docs, :content_type => :json, :accept => :json
end
end