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, Files, GroupAccessRequests, GroupBadges, 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
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #api_methods ⇒ Object
- #api_methods_help ⇒ 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 ⇒ 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
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) end |
#api_methods_help ⇒ Object
29 30 31 32 33 |
# File 'lib/labclient/common.rb', line 29 def api_methods_help puts group_name puts ' Available Methods' puts " #{api_methods.sort.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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/labclient/common.rb', line 59 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
75 76 77 78 |
# File 'lib/labclient/common.rb', line 75 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
80 81 82 83 84 |
# File 'lib/labclient/common.rb', line 80 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
87 88 89 |
# File 'lib/labclient/common.rb', line 87 def format_time?(time) time.respond_to?(:to_time) end |
#group_name ⇒ Object
Category and Primary Key for docs
41 42 43 |
# File 'lib/labclient/common.rb', line 41 def group_name self.class.instance_variable_get('@group_name') || klass end |
#help ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/labclient/common.rb', line 18 def help api_methods_help LabClient::Docs.docs[group_name].each do |key, group| puts "\n=====[ #{key} ]=====" group.select { |x| x[:example] }.each { |x| puts "#{x[:example]}\n" } end nil end |
#inspect ⇒ Object
45 46 47 48 |
# File 'lib/labclient/common.rb', line 45 def inspect api_methods_help "#<LabClient::Client url: \"#{client.settings[:url]}\">" end |
#klass ⇒ Object
Helper to get docs
36 37 38 |
# File 'lib/labclient/common.rb', line 36 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
111 112 113 |
# File 'lib/labclient/common.rb', line 111 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
100 101 102 |
# File 'lib/labclient/common.rb', line 100 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
91 92 93 94 95 |
# File 'lib/labclient/common.rb', line 91 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 |