Class: Fbup::GitHubConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/fbup/github_config.rb

Class Method Summary collapse

Instance Method Summary collapse

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
# 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)

                            }
  end
end

#find(key) ⇒ Object Also known as: []

find (full) record by key



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fbup/github_config.rb', line 70

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



87
88
89
90
91
# File 'lib/fbup/github_config.rb', line 87

def find_repo( key )
   rec = _find( key )

   rec ? "#{rec['owner']}/#{rec['name']}" : nil
end