Class: Github::Ext
- Inherits:
-
Object
- Object
- Github::Ext
- Defined in:
- lib/mushin_ext_github.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #check_params(*keys) ⇒ Object
-
#initialize(app = nil, opts = {}, params = {}) ⇒ Ext
constructor
A new instance of Ext.
Constructor Details
#initialize(app = nil, opts = {}, params = {}) ⇒ Ext
Returns a new instance of Ext.
9 10 11 12 13 |
# File 'lib/mushin_ext_github.rb', line 9 def initialize app=nil, opts={}, params={} @app = app @opts = opts @params = params end |
Instance Method Details
#call(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mushin_ext_github.rb', line 19 def call env env ||= Hash.new case @opts[:cqrs] when :cqrs_query #inbound code @app.call(env) #outbound code when :cqrs_command #inbound code @client = Octokit::Client.new(:login => @opts[:auth_username], :password => @opts[:auth_password]) user = @client.user env[:login] = user.login #TODO in case of private repos the clone_url should be prefixed with a token and passed to other domain extenstions to handle the local work if check_params(:username, :reponame) then @slug = @params[:username] + "/" + @params[:reponame] elsif check_params(:slug) then @slug = @params[:slug] end env[:slug] = @slug env[:repo_metadata] = @client.repo(@slug).to_h unless @slug.nil? env[:clone_url] = @client.repo(@slug).clone_url unless @slug.nil? @app.call(env) #outbound code else raise "you must specifiy if your cqrs call is command or query?" end end |
#check_params(*keys) ⇒ Object
15 16 17 |
# File 'lib/mushin_ext_github.rb', line 15 def check_params *keys return (keys.all? {|key| (@params.key?(key) && !@params[key].nil?)}) end |