Class: Keys

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh_key_hub/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Keys

Returns a new instance of Keys



6
7
8
9
# File 'lib/ssh_key_hub/dsl.rb', line 6

def initialize(&block)
  self.evaluate(&block)
  puts "k #{@export}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



16
17
18
# File 'lib/ssh_key_hub/dsl.rb', line 16

def method_missing(method, *args, &block)
  @self_before_instance_eval.send method, *args, &block
end

Instance Method Details

#add(new_creds) ⇒ Object



29
30
31
32
# File 'lib/ssh_key_hub/dsl.rb', line 29

def add(new_creds)
  @credentials ||= {}
  @credentials.merge!(new_creds) { |_, old_val, new_val| old_val + new_val }
end

#evaluate(&block) ⇒ Object



11
12
13
14
# File 'lib/ssh_key_hub/dsl.rb', line 11

def evaluate(&block)
  @self_before_instance_eval = eval "self", block.binding
  instance_eval &block
end

#exportObject



20
21
22
# File 'lib/ssh_key_hub/dsl.rb', line 20

def export
  @export = true
end

#github(org:, team: nil, **kwargs, &block) ⇒ Object

access_token, api_endpoint



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ssh_key_hub/dsl.rb', line 35

def github(org:, team: nil, **kwargs, &block)
  gh = SSHKeyHub::Provider::GitHub.new(kwargs)
  if block_given?
    Class.new(Keys) do
      def initialize(gh, org, team, &block)
        puts 'inner block'
        @credentials = gh.keys_for(org, team)
        @self_before_instance_eval = eval "self", block.binding
        instance_eval &block
        puts @credentials
        puts "endofinner kk #{@export}"
      end
    end.new(gh, org, team, &block)
  else
    add gh.keys_for(org, team)
  end
end

#gitlab(group:, project: nil, **kwargs) ⇒ Object



53
54
55
56
# File 'lib/ssh_key_hub/dsl.rb', line 53

def gitlab(group:, project: nil, **kwargs)
  gl = SSHKeyHub::Provider::GitLab.new(kwargs)
  add gl.keys_for(group, project)
end

#reject_weakObject



24
25
26
27
# File 'lib/ssh_key_hub/dsl.rb', line 24

def reject_weak
  filter = SSHKeyHub::Processor::KeysFilter.new @credentials
  @credentials = filter.reject_weak
end