Class: Ghsync::Config
- Inherits:
-
Object
- Object
- Ghsync::Config
- Defined in:
- lib/ghsync/config.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#organizations ⇒ Object
readonly
Returns the value of attribute organizations.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#repositories ⇒ Object
readonly
Returns the value of attribute repositories.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
- .config_path ⇒ Object
- .create(import_from_pra: true) ⇒ Object
- .import_from_pra ⇒ Object
- .json_parse(content) ⇒ Object
- .load_config ⇒ Object
- .parse_config_file ⇒ Object
- .parse_pra_config_file ⇒ Object
- .pra_config_path ⇒ Object
- .read_config_file(path) ⇒ Object
- .users_home_directory ⇒ Object
Instance Method Summary collapse
-
#initialize(config) ⇒ Config
constructor
Organization config { “name”: “org”, “exclude”: [“repo”], “base_path”: “org” #optional } Repository config { “owner”: “owner”, “name”: “repo”, “base_path”: “repo” #optional }.
Constructor Details
#initialize(config) ⇒ Config
Organization config
"name": "org",
"exclude": ["repo"],
"base_path": "org" #optional
Repository config
"owner": "owner",
"name": "repo",
"base_path": "repo" #optional
19 20 21 22 23 24 25 26 |
# 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 |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/ghsync/config.rb', line 5 def base_path @base_path end |
#organizations ⇒ Object (readonly)
Returns the value of attribute organizations.
5 6 7 |
# File 'lib/ghsync/config.rb', line 5 def organizations @organizations end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
5 6 7 |
# File 'lib/ghsync/config.rb', line 5 def password @password end |
#repositories ⇒ Object (readonly)
Returns the value of attribute repositories.
5 6 7 |
# File 'lib/ghsync/config.rb', line 5 def repositories @repositories end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/ghsync/config.rb', line 5 def username @username end |
Class Method Details
.config_path ⇒ Object
61 62 63 64 65 |
# 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) ⇒ Object
28 29 |
# File 'lib/ghsync/config.rb', line 28 def self.create(import_from_pra: true) end |
.import_from_pra ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
79 80 81 |
# File 'lib/ghsync/config.rb', line 79 def self.json_parse(content) return JSON.parse(content) end |
.load_config ⇒ Object
42 43 44 |
# File 'lib/ghsync/config.rb', line 42 def self.load_config return self.new(self.parse_config_file) end |
.parse_config_file ⇒ Object
46 47 48 |
# 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 ⇒ Object
50 51 52 |
# 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 ⇒ Object
67 68 69 70 71 72 73 |
# 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) ⇒ Object
54 55 56 57 58 59 |
# 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 ⇒ Object
75 76 77 |
# File 'lib/ghsync/config.rb', line 75 def self.users_home_directory return ENV['HOME'] end |