Class: Txgh::TxBranchResource

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/txgh/tx_branch_resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, branch) ⇒ TxBranchResource

Returns a new instance of TxBranchResource.



32
33
34
35
# File 'lib/txgh/tx_branch_resource.rb', line 32

def initialize(resource, branch)
  @resource = resource
  @branch = branch
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



12
13
14
# File 'lib/txgh/tx_branch_resource.rb', line 12

def branch
  @branch
end

#resourceObject (readonly)

Returns the value of attribute resource.



12
13
14
# File 'lib/txgh/tx_branch_resource.rb', line 12

def resource
  @resource
end

Class Method Details

.deslugify(resource_slug, branch) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/txgh/tx_branch_resource.rb', line 21

def deslugify(resource_slug, branch)
  suffix = "-#{Utils.slugify(branch)}"

  if resource_slug.end_with?(suffix)
    resource_slug.chomp(suffix)
  else
    resource_slug
  end
end

.find(tx_config, resource_slug, branch) ⇒ Object



15
16
17
18
19
# File 'lib/txgh/tx_branch_resource.rb', line 15

def find(tx_config, resource_slug, branch)
  resource_slug = deslugify(resource_slug, branch)
  resource = tx_config.resource(resource_slug)
  new(resource, branch) if resource
end

Instance Method Details

#has_branch?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/txgh/tx_branch_resource.rb', line 52

def has_branch?
  true
end

#resource_slugObject



37
38
39
# File 'lib/txgh/tx_branch_resource.rb', line 37

def resource_slug
  "#{resource.resource_slug}-#{slugified_branch}"
end

#slugsObject



41
42
43
# File 'lib/txgh/tx_branch_resource.rb', line 41

def slugs
  [project_slug, resource_slug]
end

#to_hObject



45
46
47
48
49
50
# File 'lib/txgh/tx_branch_resource.rb', line 45

def to_h
  resource.to_h.merge(
    project_slug: project_slug,
    resource_slug: resource_slug
  )
end