Class: Codily::Elements::ServiceBelonggingBase

Inherits:
Base
  • Object
show all
Defined in:
lib/codily/elements/service_belongging_base.rb

Instance Attribute Summary

Attributes inherited from Base

#fastly_obj, #root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#as_dsl_hash, def_attr, defaults, #dsl_args, #id, #inspect, #name, name_for_attr, #parent, #parent_class, #parents, path

Constructor Details

#initializeServiceBelonggingBase

Returns a new instance of ServiceBelonggingBase.



8
9
10
11
12
13
14
15
16
17
# File 'lib/codily/elements/service_belongging_base.rb', line 8

def initialize(*)
  super

  if fastly_obj
    service_version = root.service_version_get(fastly_obj.service_id)
    raise "[bug?] Root#service_version_set should be called before passing fastly obj to ServiceBelonggingBase.new" unless service_version
    @hash[:_service_name] = service_version[:name]
    @hash[:_service_id] = service_version[:id]
  end
end

Class Method Details

.parent_classObject



19
20
21
# File 'lib/codily/elements/service_belongging_base.rb', line 19

def self.parent_class
  Service
end

Instance Method Details

#as_hashObject



46
47
48
# File 'lib/codily/elements/service_belongging_base.rb', line 46

def as_hash
  @hash.reject { |k,v| k == :_service_name || k == :_service_id }
end

#keyObject



42
43
44
# File 'lib/codily/elements/service_belongging_base.rb', line 42

def key
  [service_name, name]
end

#parent_keyObject



23
24
25
# File 'lib/codily/elements/service_belongging_base.rb', line 23

def parent_key
  service_name
end

#service_idObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/codily/elements/service_belongging_base.rb', line 27

def service_id
  @hash[:_service_id] ||= begin
    service_version = root.service_version_get(service_name)
    if service_version
      service_version[:id]
    else
      nil
    end
  end
end

#service_nameObject



38
39
40
# File 'lib/codily/elements/service_belongging_base.rb', line 38

def service_name
  @hash[:_service_name]
end