Class: VCAP::Services::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/base/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Service

Returns a new instance of Service.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/base/service.rb', line 11

def initialize(attrs)
  @unique_id = attrs.fetch('unique_id')
  @label = attrs['label']
  @active = attrs['active']
  @active = true if @active.nil?
  @tags = attrs['tags']
  @plan_options = attrs['plan_options']
  @acls = attrs['acls']
  @timeout = attrs['timeout']
  @default_plan = attrs['default_plan']
  @supported_versions = attrs['supported_versions']
  @version_aliases = attrs['version_aliases']
  @extra = attrs.fetch('extra')
  @info_url = attrs['info_url']
  @documentation_url = attrs['documentation_url']
  @bindable = attrs.fetch('bindable', true)
  @guid = attrs['guid']
  @description = attrs['description']
  @provider = attrs.fetch('provider')
  @version = attrs.fetch('version')
  @url = attrs.fetch('url')
  @plans = Plan.plan_hash_as_plan_array(attrs.fetch('plans'))
  @tags = attrs['tags']
end

Instance Attribute Details

#aclsObject (readonly)

Returns the value of attribute acls.



6
7
8
# File 'lib/base/service.rb', line 6

def acls
  @acls
end

#activeObject (readonly)

Returns the value of attribute active.



6
7
8
# File 'lib/base/service.rb', line 6

def active
  @active
end

#bindableObject (readonly)

Returns the value of attribute bindable.



6
7
8
# File 'lib/base/service.rb', line 6

def bindable
  @bindable
end

#default_planObject (readonly)

Returns the value of attribute default_plan.



6
7
8
# File 'lib/base/service.rb', line 6

def default_plan
  @default_plan
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/base/service.rb', line 6

def description
  @description
end

#documentation_urlObject (readonly)

Returns the value of attribute documentation_url.



6
7
8
# File 'lib/base/service.rb', line 6

def documentation_url
  @documentation_url
end

#extraObject (readonly)

Returns the value of attribute extra.



6
7
8
# File 'lib/base/service.rb', line 6

def extra
  @extra
end

#guidObject

Returns the value of attribute guid.



9
10
11
# File 'lib/base/service.rb', line 9

def guid
  @guid
end

#info_urlObject (readonly)

Returns the value of attribute info_url.



6
7
8
# File 'lib/base/service.rb', line 6

def info_url
  @info_url
end

#labelObject (readonly)

Returns the value of attribute label.



6
7
8
# File 'lib/base/service.rb', line 6

def label
  @label
end

#plan_optionsObject (readonly)

Returns the value of attribute plan_options.



6
7
8
# File 'lib/base/service.rb', line 6

def plan_options
  @plan_options
end

#plansObject (readonly)

Returns the value of attribute plans.



6
7
8
# File 'lib/base/service.rb', line 6

def plans
  @plans
end

#providerObject (readonly)

Returns the value of attribute provider.



6
7
8
# File 'lib/base/service.rb', line 6

def provider
  @provider
end

#supported_versionsObject (readonly)

Returns the value of attribute supported_versions.



6
7
8
# File 'lib/base/service.rb', line 6

def supported_versions
  @supported_versions
end

#tagsObject (readonly)

Returns the value of attribute tags.



6
7
8
# File 'lib/base/service.rb', line 6

def tags
  @tags
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



6
7
8
# File 'lib/base/service.rb', line 6

def timeout
  @timeout
end

#unique_idObject (readonly)

Returns the value of attribute unique_id.



6
7
8
# File 'lib/base/service.rb', line 6

def unique_id
  @unique_id
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/base/service.rb', line 6

def url
  @url
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/base/service.rb', line 6

def version
  @version
end

#version_aliasesObject (readonly)

Returns the value of attribute version_aliases.



6
7
8
# File 'lib/base/service.rb', line 6

def version_aliases
  @version_aliases
end

Instance Method Details

#create_change_set(service_in_ccdb) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/base/service.rb', line 36

def create_change_set(service_in_ccdb)

  if service_in_ccdb
    service_guid    = service_in_ccdb.guid
    plans_to_update = []
    plans_to_add    = []

    self.plans.each do |catalog_plan|
      ccdb_plan = service_in_ccdb.plans.find { |ccp| catalog_plan.unique_id == ccp.unique_id }
      ccdb_plan = service_in_ccdb.plans.find { |ccp| catalog_plan.name.to_s == ccp.name.to_s } unless ccdb_plan

      if ccdb_plan
        catalog_plan.guid = ccdb_plan.guid
        plans_to_update << catalog_plan
      else
        plans_to_add << catalog_plan
      end
    end
  else
    service_guid    = nil
    plans_to_add    = self.plans
    plans_to_update = []
  end

  ServicePlanChangeSet.new(self, service_guid,
    plans_to_add: plans_to_add,
    plans_to_update: plans_to_update,
  )
end

#same_tuple?(other) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
88
89
90
91
# File 'lib/base/service.rb', line 85

def same_tuple?(other)
  [self.label, self.provider, self.version].each { |x| return false if x.nil? }

  (self.label == other.label &&
    self.provider == other.provider &&
    self.version == other.version)
end

#to_hashObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/base/service.rb', line 66

def to_hash
  {
    "description" => description,
    "provider" => provider,
    "version" => version,
    "url" => url,
    "documentation_url" => documentation_url,
    "plans" => Plan.plans_array_to_hash(plans),
    "unique_id" => unique_id,
    "label" => label,
    "active" => active,
    "acls" => acls,
    "timeout" => timeout,
    "extra" => extra,
    "bindable" => bindable,
    "tags" => tags
  }
end