Class: Overlay::GithubRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/overlay/configuration.rb

Overview

Optional parameters: :branch, :use_publisher :registration_address :redis_server :redis_port :endpoint, :site,

Constant Summary collapse

REQUIRED_PARAMS =
[:org, :repo, :auth, :root_source_path]
REQUIRED_PUBLISHER_PARAMS =
[:redis_server, :redis_port, :registration_server]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GithubRepo

Returns a new instance of GithubRepo.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/overlay/configuration.rb', line 60

def initialize(options={})
  @org                  = options[:org]
  @repo                 = options[:repo]
  @auth                 = options[:auth]
  @root_source_path     = options[:root_source_path]
  @root_dest_path       = options[:root_dest_path]
  @redis_server         = options[:redis_server]
  @redis_port           = options[:redis_port]
  @registration_server  = options[:registration_server]
  @endpoint             = options[:endpoint]
  @site                 = options[:site]
  @branch               = options[:branch] || 'master'
  @use_publisher        = options[:use_publisher] || false

  # Quick sanity check
  validate

  # Create a hook to the Github API
  initialize_api
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



52
53
54
# File 'lib/overlay/configuration.rb', line 52

def auth
  @auth
end

#branchObject

Returns the value of attribute branch.



50
51
52
# File 'lib/overlay/configuration.rb', line 50

def branch
  @branch
end

#endpointObject

Returns the value of attribute endpoint.



52
53
54
# File 'lib/overlay/configuration.rb', line 52

def endpoint
  @endpoint
end

#github_apiObject

Internal repo api hook



55
56
57
# File 'lib/overlay/configuration.rb', line 55

def github_api
  @github_api
end

#orgObject (readonly)

Returns the value of attribute org.



52
53
54
# File 'lib/overlay/configuration.rb', line 52

def org
  @org
end

#redis_portObject

Returns the value of attribute redis_port.



51
52
53
# File 'lib/overlay/configuration.rb', line 51

def redis_port
  @redis_port
end

#redis_serverObject

Returns the value of attribute redis_server.



51
52
53
# File 'lib/overlay/configuration.rb', line 51

def redis_server
  @redis_server
end

#registration_serverObject

Returns the value of attribute registration_server.



51
52
53
# File 'lib/overlay/configuration.rb', line 51

def registration_server
  @registration_server
end

#repoObject (readonly)

Returns the value of attribute repo.



52
53
54
# File 'lib/overlay/configuration.rb', line 52

def repo
  @repo
end

#root_dest_pathObject

Returns the value of attribute root_dest_path.



50
51
52
# File 'lib/overlay/configuration.rb', line 50

def root_dest_path
  @root_dest_path
end

#root_source_pathObject

Returns the value of attribute root_source_path.



50
51
52
# File 'lib/overlay/configuration.rb', line 50

def root_source_path
  @root_source_path
end

#siteObject

Returns the value of attribute site.



52
53
54
# File 'lib/overlay/configuration.rb', line 52

def site
  @site
end

#use_publisherObject

Returns the value of attribute use_publisher.



51
52
53
# File 'lib/overlay/configuration.rb', line 51

def use_publisher
  @use_publisher
end

Instance Method Details

#after_process_hook(&hook) ⇒ Object

Add code to be called after processing a hook

Raises:

  • (ArgumentError)


110
111
112
113
# File 'lib/overlay/configuration.rb', line 110

def after_process_hook(&hook)
  raise ArgumentError, "No block given" unless block_given?
  @post_hook = hook
end

#initialize_apiObject

Retrieve API hook to repo



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/overlay/configuration.rb', line 121

def initialize_api
  @github_api = ::Github::Repos.new do |github_config|
    github_config.endpoint    = @endpoint if @endpoint
    github_config.site        = @site if @site
    github_config.basic_auth  = @auth
    github_config.repo        = @repo
    github_config.org         = @org
    github_config.adapter     = :net_http
    github_config.ssl         = {:verify => false}
  end
end

#post_hookObject

Run post_hook code



116
117
118
# File 'lib/overlay/configuration.rb', line 116

def post_hook
  @post_hook.call unless @post_hook.nil?
end

#validateObject

Make sure that this configuration has all required parameters



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/overlay/configuration.rb', line 96

def validate
  REQUIRED_PARAMS.each do |param|
    raise RequiredParameterError, "Overlay GithubRepo missing required paramater: #{param}" if (send(param).nil? || send(param).empty?)
  end

  # If we are using a publisher, check required publisher params
  if @use_publisher
    REQUIRED_PUBLISHER_PARAMS.each do |param|
      raise RequiredParameterError, "Overlay GithubRepo missing required paramater: #{param}" if (send(param).nil?)
    end
  end
end