module SocialSnippet::Api::ManifestApi
Public Instance Methods
init_manifest(options = {})
click to toggle source
Initialize the snippet.json interactively. $ sspm init
# File lib/social_snippet/api/manifest_api.rb, line 5 def init_manifest(options = {}) current_answers = load_manifest_file || {} answer = loop_manifest_questions(current_answers) core.storage.write "snippet.json", ::JSON.pretty_generate(answer) answer end
Private Instance Methods
ask_confirm(message)
click to toggle source
# File lib/social_snippet/api/manifest_api.rb, line 34 def ask_confirm(message) ret = core.prompt.ask(message) do |q| q.limit = 1 q.validate = /^[yn]$/i end /y/i === ret end
ask_manifest_question(question)
click to toggle source
# File lib/social_snippet/api/manifest_api.rb, line 49 def ask_manifest_question(question) if question[:type] === :string core.prompt.ask("#{question[:key]}: ") do |q| q.default = question[:default] if question[:validate].is_a?(Regexp) q.validate = question[:validate] end end end end
ask_manifest_questions(questions, obj)
click to toggle source
# File lib/social_snippet/api/manifest_api.rb, line 42 def ask_manifest_questions(questions, obj) questions.inject(obj) do |obj, q| obj[q[:key]] = ask_manifest_question(q) obj end end
load_manifest_file()
click to toggle source
load current configuration
# File lib/social_snippet/api/manifest_api.rb, line 26 def load_manifest_file if core.storage.exists?("snippet.json") ::JSON.parse(core.storage.read "snippet.json") else nil end end
loop_manifest_questions(answer)
click to toggle source
# File lib/social_snippet/api/manifest_api.rb, line 14 def loop_manifest_questions(answer) loop do answer = ask_manifest_questions(manifest_questions(answer), answer) output "" output ::JSON.pretty_generate(answer) output "" break if ask_confirm("Is this okay? [Y/N]: ") end answer end
manifest_questions(answer)
click to toggle source
# File lib/social_snippet/api/manifest_api.rb, line 60 def manifest_questions(answer) [ { :key => "name", :type => :string, :validate => /[a-zA-Z0-9\.\-_]+/, :default => answer["name"], }, { :key => "description", :type => :string, :default => answer["description"], }, { :key => "license", :default => answer["license"] || "MIT", :type => :string, }, ] end