Class: Avm::Gitlab::RestApi::NodesSet

Inherits:
Object
  • Object
show all
Defined in:
lib/avm/gitlab/rest_api/nodes_set.rb

Constant Summary collapse

IDS_PREFIXES =
{
  '@@' => :group_and_projects, '@-' => :group_projects, '@' => :group
}.freeze
GROUP_AND_PROJECTS_ID_PARSER =
/\A\@@(.*)\z/.to_parser { |m| m[1] }
GROUP_ID_PARSER =
/\A\@(.*)\z/.to_parser { |m| m[1] }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rest_api, *ids) ⇒ NodesSet

Returns a new instance of NodesSet.



33
34
35
36
# File 'lib/avm/gitlab/rest_api/nodes_set.rb', line 33

def initialize(rest_api, *ids)
  self.rest_api = rest_api
  ids.each { |id| add(id) }
end

Instance Attribute Details

#rest_apiObject

Returns the value of attribute rest_api.



31
32
33
# File 'lib/avm/gitlab/rest_api/nodes_set.rb', line 31

def rest_api
  @rest_api
end

Class Method Details

.parse_id(id) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/avm/gitlab/rest_api/nodes_set.rb', line 20

def parse_id(id)
  IDS_PREFIXES.each do |prefix, type|
    /\A#{::Regexp.quote(prefix)}(.*)\z/.if_match(id, false) do |m|
      return [m[1], type]
    end
  end

  [id, :project]
end

Instance Method Details

#add(id) ⇒ Object



38
39
40
41
42
# File 'lib/avm/gitlab/rest_api/nodes_set.rb', line 38

def add(id)
  parsed_id, type = self.class.parse_id(id)

  send("add_by_#{type}_id", parsed_id)
end

#groupArray<Avm::Gitlab::RestApi::Group>

Returns:



45
46
47
# File 'lib/avm/gitlab/rest_api/nodes_set.rb', line 45

def group
  nodes.select { |node| node.is_a?(::Avm::Gitlab::RestApi::Group) }
end

#nodesArray<Avm::Gitlab::RestApi::Node>

Returns:



55
56
57
# File 'lib/avm/gitlab/rest_api/nodes_set.rb', line 55

def nodes
  nodes_set.sort_by { |p| [p.full_path] }
end

#projectsArray<Avm::Gitlab::RestApi::Project>

Returns:



50
51
52
# File 'lib/avm/gitlab/rest_api/nodes_set.rb', line 50

def projects
  nodes.select { |node| node.is_a?(::Avm::Gitlab::RestApi::Project) }
end