Class: Avm::Gitlab::RestApi::NodesSet
- Inherits:
-
Object
- Object
- Avm::Gitlab::RestApi::NodesSet
- 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
-
#rest_api ⇒ Object
readonly
Returns the value of attribute rest_api.
Class Method Summary collapse
Instance Method Summary collapse
- #add(id) ⇒ Object
- #group ⇒ Array<Avm::Gitlab::RestApi::Group>
-
#initialize(rest_api, *ids) ⇒ NodesSet
constructor
A new instance of NodesSet.
- #nodes ⇒ Array<Avm::Gitlab::RestApi::Node>
- #projects ⇒ Array<Avm::Gitlab::RestApi::Project>
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_api ⇒ Object
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 |
#group ⇒ Array<Avm::Gitlab::RestApi::Group>
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 |
#nodes ⇒ Array<Avm::Gitlab::RestApi::Node>
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 |
#projects ⇒ Array<Avm::Gitlab::RestApi::Project>
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 |