Class: LabClient::Common
- Inherits:
-
Object
- Object
- LabClient::Common
- Extended by:
- Docs
- Includes:
- AccessLevel
- Defined in:
- lib/labclient/common.rb
Overview
Shared Methods
Direct Known Subclasses
Appearances, ApplicationSettings, ApplicationStatistics, Applications, Approvals, AuditEvents, Avatars, Awards, Branches, BroadcastMessages, CiLint, CommitDiscussions, Commits, DeployKeys, Discussions, EpicDiscussions, EpicNotes, Epics, Events, FeatureFlags, Files, GroupAccessRequests, GroupBadges, GroupClusters, GroupHooks, GroupLabels, GroupLdap, GroupMembers, GroupMilestones, Groups, ImpersonationTokens, IssueAwards, IssueDiscussions, IssueNotes, Issues, Jobs, Keys, Licenses, Markdown, Members, MergeRequestApprovals, MergeRequestAwards, MergeRequestDiscussions, MergeRequestNotes, MergeRequests, Namespaces, Notes, Notifications, PipelineSchedules, PipelineVariables, Pipelines, ProjectAccessRequests, ProjectApprovals, ProjectBadges, ProjectClusters, ProjectDeployments, ProjectEnvironments, ProjectHooks, ProjectLabels, ProjectMembers, ProjectMilestones, ProjectMirrors, ProjectReleaseLinks, ProjectReleases, ProjectRunners, ProjectServices, ProjectSnippets, ProjectTriggers, ProjectVariables, Projects, ProtectedBranches, ProtectedEnvironments, ProtectedTags, PushRules, Registry, Repositories, ResourceLabelEpics, ResourceLabelIssues, ResourceLabelMergeRequests, ResourceLabels, Runners, SnippetAwards, SnippetDiscussions, SnippetNotes, Snippets, SystemHooks, Tags, Todos, UserEmails, UserGpgKeys, UserKeys, Users, Version, Wikis
Constant Summary
Constants included from AccessLevel
AccessLevel::HUMAN_ACCESS_LEVELS, AccessLevel::MACHINE_ACCESS_LEVELS
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #api_methods ⇒ Object
- #api_methods_help(help_filter = nil) ⇒ Object
-
#format_id(obj_id) ⇒ Object
Query Helpers ======================= URL Encoding Object ID Transformation “1” == 1, 1 => 1, “1” => 1 nil => nil ‘group/name’ => group%F2name LabClient::Class => id.
- #format_query_id(key, query) ⇒ Object
- #format_query_ids(key, query) ⇒ Object
-
#format_time?(time) ⇒ Boolean
Formatting Time Helper.
-
#group_name ⇒ Object
Category and Primary Key for docs.
- #help(help_filter = nil) ⇒ Object
-
#initialize(client) ⇒ Common
constructor
A new instance of Common.
- #inspect ⇒ Object
-
#klass ⇒ Object
Helper to get docs.
-
#protected_query_access_level(query, key = :push_access_level) ⇒ Object
TODO: See if these are even needed Protected Branches Convert Symbol to Integer Numbers 0 => No access 30 => Developer access 40 => Maintainer access 60 => Admin access.
-
#query_access_level(query, key = :group_access) ⇒ Object
Convert Symbol to Integer Numbers :developer => 30 :owner => 50.
- #query_format_time(query, key) ⇒ Object
Methods included from Docs
demo, desc, doc, docs, example, json, markdown, navigation, option, result, subtitle, title
Methods included from AccessLevel
#human_access_level, #human_protected_access_level, #machine_access_level, #machine_protected_access_level
Constructor Details
#initialize(client) ⇒ Common
Returns a new instance of Common.
10 11 12 |
# File 'lib/labclient/common.rb', line 10 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/labclient/common.rb', line 8 def client @client end |
Instance Method Details
#api_methods ⇒ Object
14 15 16 |
# File 'lib/labclient/common.rb', line 14 def api_methods public_methods(false).sort end |
#api_methods_help(help_filter = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/labclient/common.rb', line 31 def api_methods_help(help_filter = nil) puts group_name puts ' Available Methods' shown_subclasses = if help_filter api_methods.grep(/#{help_filter}/) else api_methods end puts " #{shown_subclasses.join(' ')}\n" end |
#format_id(obj_id) ⇒ Object
Query Helpers
URL Encoding Object ID Transformation “1” == 1, 1 => 1, “1” => 1 nil => nil ‘group/name’ => group%F2name LabClient::Class => id
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/labclient/common.rb', line 68 def format_id(obj_id) # Return if Empty return nil if obj_id.nil? # Already a Integer return obj_id if obj_id.class == Integer # If LabClient Object, send ID return obj_id.id if obj_id.class.module_parent_name == 'LabClient' # Valid Integer in String return obj_id if /\A\d+\z/.match(obj_id) CGI.escape obj_id.to_s end |
#format_query_id(key, query) ⇒ Object
84 85 86 87 |
# File 'lib/labclient/common.rb', line 84 def format_query_id(key, query) query[key] = format_id(query[key]) if query.key? key query[key.to_s] = format_id(query[key.to_s]) if query.key? key.to_s end |
#format_query_ids(key, query) ⇒ Object
89 90 91 92 93 |
# File 'lib/labclient/common.rb', line 89 def format_query_ids(key, query) query[key] = query[key].map { |x| format_id(x) } if query.key? key query[key.to_s] = query[key.to_s].map { |x| format_id(x) } if query.key? key.to_s end |
#format_time?(time) ⇒ Boolean
Formatting Time Helper
96 97 98 |
# File 'lib/labclient/common.rb', line 96 def format_time?(time) time.respond_to?(:to_time) end |
#group_name ⇒ Object
Category and Primary Key for docs
50 51 52 |
# File 'lib/labclient/common.rb', line 50 def group_name self.class.instance_variable_get('@group_name') || klass end |
#help(help_filter = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/labclient/common.rb', line 18 def help(help_filter = nil) api_methods_help(help_filter) LabClient::Docs.docs[group_name]&.each do |key, group| next if help_filter && !key.downcase.include?(help_filter.to_s) puts "\n=====[ #{key} ]=====" group.select { |x| x[:example] }.each { |x| puts "#{x[:example]}\n" } end nil end |
#inspect ⇒ Object
54 55 56 57 |
# File 'lib/labclient/common.rb', line 54 def inspect api_methods_help "#<LabClient::Client url: \"#{client.settings[:url]}\">" end |
#klass ⇒ Object
Helper to get docs
45 46 47 |
# File 'lib/labclient/common.rb', line 45 def klass self.class.name.split('::', 2).last.split(/(?=[A-Z])/).join(' ') end |
#protected_query_access_level(query, key = :push_access_level) ⇒ Object
TODO: See if these are even needed Protected Branches Convert Symbol to Integer Numbers 0 => No access 30 => Developer access 40 => Maintainer access 60 => Admin access
120 121 122 |
# File 'lib/labclient/common.rb', line 120 def protected_query_access_level(query, key = :push_access_level) query[key] = machine_protected_access_level query[key] if query.key?(key) && query[key].class == Symbol end |
#query_access_level(query, key = :group_access) ⇒ Object
Convert Symbol to Integer Numbers :developer => 30 :owner => 50
109 110 111 |
# File 'lib/labclient/common.rb', line 109 def query_access_level(query, key = :group_access) query[key] = machine_access_level query[key] if query.key?(key) && query[key].class == Symbol end |
#query_format_time(query, key) ⇒ Object
100 101 102 103 104 |
# File 'lib/labclient/common.rb', line 100 def query_format_time(query, key) return false unless query.key?(key) && format_time?(query[key]) query[key] = query[key].to_time.utc.iso8601 end |