class Ghsync::Config
Attributes
base_path[R]
organizations[R]
password[R]
repositories[R]
username[R]
Public Class Methods
config_path()
click to toggle source
# File lib/ghsync/config.rb, line 61 def self.config_path if File.exists?(File.join(self.users_home_directory, '.ghsync', 'config.json')) return File.join(self.users_home_directory, '.ghsync', 'config.json') end end
create(import_from_pra: true)
click to toggle source
# File lib/ghsync/config.rb, line 28 def self.create(import_from_pra: true) end
import_from_pra()
click to toggle source
# File lib/ghsync/config.rb, line 31 def self.import_from_pra pra_config = Config.parse_pra_config_file github_config = pra_config["pull_sources"].select {|source| source["type"] == "github"}.first unless github_config.nil? @organizations += github_config["config"]["organizations"] @repositories += github_config["config"]["repositories"] @username ||= github_config["config"]["username"] @password ||= github_config["config"]["password"] end end
json_parse(content)
click to toggle source
# File lib/ghsync/config.rb, line 79 def self.json_parse(content) return JSON.parse(content) end
load_config()
click to toggle source
# File lib/ghsync/config.rb, line 42 def self.load_config return self.new(self.parse_config_file) end
new(config)
click to toggle source
Organization config {
"name": "org", "exclude": ["repo"], "base_path": "org" #optional
} Repository config {
"owner": "owner", "name": "repo", "base_path": "repo" #optional
}
# File lib/ghsync/config.rb, line 19 def initialize(config) @organizations = config["organizations"] || [] @repositories = config["repositories"] || [] @username = config["username"] @password = config["password"] @base_path = config["base_path"] import_from_pra if config["use_pra"] end
parse_config_file()
click to toggle source
# File lib/ghsync/config.rb, line 46 def self.parse_config_file self.json_parse(self.read_config_file(config_path)) end
parse_pra_config_file()
click to toggle source
# File lib/ghsync/config.rb, line 50 def self.parse_pra_config_file self.json_parse(self.read_config_file(pra_config_path)) end
pra_config_path()
click to toggle source
# File lib/ghsync/config.rb, line 67 def self.pra_config_path if File.exists?(File.join(self.users_home_directory, '.pra', 'config.json')) return File.join(self.users_home_directory, '.pra', 'config.json') else return File.join(self.users_home_directory, '.pra.json') end end
read_config_file(path)
click to toggle source
# File lib/ghsync/config.rb, line 54 def self.read_config_file(path) file = File.open(path, "r") contents = file.read file.close return contents end
users_home_directory()
click to toggle source
# File lib/ghsync/config.rb, line 75 def self.users_home_directory return ENV['HOME'] end