Class: GlueGun::Model::ServiceRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/glue_gun/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#servicesObject

Returns the value of attribute services.



8
9
10
# File 'lib/glue_gun/model.rb', line 8

def services
  @services
end

Instance Method Details

#[](k) ⇒ Object



23
24
25
26
27
28
# File 'lib/glue_gun/model.rb', line 23

def [](k)
  return nil if k.nil?

  @services ||= {}
  @services.dig(k.to_sym)
end

#[]=(k, v) ⇒ Object



19
20
21
# File 'lib/glue_gun/model.rb', line 19

def []=(k, v)
  register(k, v)
end

#defaultObject



36
37
38
# File 'lib/glue_gun/model.rb', line 36

def default
  default_key.present? ? services[default_key] : nil
end

#default_keyObject



30
31
32
33
34
# File 'lib/glue_gun/model.rb', line 30

def default_key
  return unless services.keys.count == 1

  services.keys.first
end

#optionsObject



15
16
17
# File 'lib/glue_gun/model.rb', line 15

def options
  services.keys
end

#register(k, v) ⇒ Object



10
11
12
13
# File 'lib/glue_gun/model.rb', line 10

def register(k, v)
  @services ||= {}
  @services[k.to_sym] = v
end