Class: Avm::EacGitlabBase0::Api::NodesSet
- Inherits:
-
Object
- Object
- Avm::EacGitlabBase0::Api::NodesSet
- Defined in:
- lib/avm/eac_gitlab_base0/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
-
#no_groups ⇒ Object
writeonly
Sets the attribute no_groups.
-
#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::EacGitlabBase0::Api::Group>
-
#initialize(rest_api, *ids) ⇒ NodesSet
constructor
A new instance of NodesSet.
- #no_groups? ⇒ Boolean
- #nodes ⇒ Array<Avm::EacGitlabBase0::Api::Node>
- #projects ⇒ Array<Avm::EacGitlabBase0::Api::Project>
Constructor Details
#initialize(rest_api, *ids) ⇒ NodesSet
Returns a new instance of NodesSet.
34 35 36 37 |
# File 'lib/avm/eac_gitlab_base0/api/nodes_set.rb', line 34 def initialize(rest_api, *ids) self.rest_api = rest_api ids.each { |id| add(id) } end |
Instance Attribute Details
#no_groups=(value) ⇒ Object (writeonly)
Sets the attribute no_groups
32 33 34 |
# File 'lib/avm/eac_gitlab_base0/api/nodes_set.rb', line 32 def no_groups=(value) @no_groups = value end |
#rest_api ⇒ Object
Returns the value of attribute rest_api.
31 32 33 |
# File 'lib/avm/eac_gitlab_base0/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/eac_gitlab_base0/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
39 40 41 42 43 |
# File 'lib/avm/eac_gitlab_base0/api/nodes_set.rb', line 39 def add(id) parsed_id, type = self.class.parse_id(id) send("add_by_#{type}_id", parsed_id) end |
#group ⇒ Array<Avm::EacGitlabBase0::Api::Group>
46 47 48 |
# File 'lib/avm/eac_gitlab_base0/api/nodes_set.rb', line 46 def group nodes.select { |node| node.is_a?(::Avm::EacGitlabBase0::Api::Group) } end |
#no_groups? ⇒ Boolean
62 63 64 |
# File 'lib/avm/eac_gitlab_base0/api/nodes_set.rb', line 62 def no_groups? @no_groups ? true : false end |
#nodes ⇒ Array<Avm::EacGitlabBase0::Api::Node>
56 57 58 59 60 |
# File 'lib/avm/eac_gitlab_base0/api/nodes_set.rb', line 56 def nodes r = nodes_set r = r.reject { |g| g.is_a?(::Avm::EacGitlabBase0::Api::Group) } if no_groups? r.sort_by { |p| [p.full_path] } end |
#projects ⇒ Array<Avm::EacGitlabBase0::Api::Project>
51 52 53 |
# File 'lib/avm/eac_gitlab_base0/api/nodes_set.rb', line 51 def projects nodes.select { |node| node.is_a?(::Avm::EacGitlabBase0::Api::Project) } end |