Class: Fbup::GitHubConfig
- Inherits:
-
Object
- Object
- Fbup::GitHubConfig
- Defined in:
- lib/fbup/github_config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(recs) ⇒ Object
-
#find(key) ⇒ Object
(also: #[])
find (full) record by key.
- #find_repo(key) ⇒ Object
-
#initialize(recs = nil) ⇒ GitHubConfig
constructor
A new instance of GitHubConfig.
Constructor Details
#initialize(recs = nil) ⇒ GitHubConfig
Returns a new instance of GitHubConfig.
23 24 25 26 |
# File 'lib/fbup/github_config.rb', line 23 def initialize( recs=nil ) @table = {} add( recs ) if recs end |
Class Method Details
.read(path) ⇒ Object
18 19 20 21 |
# File 'lib/fbup/github_config.rb', line 18 def self.read( path ) recs = read_csv( path ) new( recs ) end |
Instance Method Details
#add(recs) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fbup/github_config.rb', line 29 def add( recs ) recs.each do |rec| path = rec['path'] ## use pathspec - why? why not? ## or repospec or such ## auto-expand to openfootball as default org if no @ specified owner, path = if path.index( '@') path.split( '@', 2 ) else ['openfootball', path ] end name, path = path.split( '/', 2 ) ## openfootball@europe/france ## => ## owner: openfootball ## name: europe ## path: france ## ## openfootball@austria ## => ## owner: openfootball ## name: austria ## path: nil @table[ rec['key'] ] = { 'owner' => owner, ## (required) 'name' => name, ## (required) 'path' => path ## extra/inner/inside/local path (optional) } ## check for/add flags flags = rec['flags'].split( /[ ]*[|][ ]*/ ) ## generte hash ## e.g. v2 | flat => { 'v2' => true, 'flat' => true } etc. flags = flags.map { |flag| [flag, true] }.to_h @table[ rec['key'] ]['flags'] = flags if flags.size > 0 end end |
#find(key) ⇒ Object Also known as: []
find (full) record by key
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fbup/github_config.rb', line 79 def find( key ) key = key.to_s.downcase ## first check for 1:1 match rec = @table[key] if rec.nil? ## try match by (country / first) code ## split by . key, _ = key.split( '.' ) rec = @table[key] end rec end |
#find_repo(key) ⇒ Object
96 97 98 99 100 |
# File 'lib/fbup/github_config.rb', line 96 def find_repo( key ) rec = _find( key ) rec ? "#{rec['owner']}/#{rec['name']}" : nil end |