Class: LabClient::Klass
Overview
Common Configuration for all Class Helpers
Direct Known Subclasses
Appearance, Application, ApplicationSetting, ApprovalRule, AuditEvent, Avatar, Award, Branch, BroadcastMessage, Changes, Commit, CommitComment, CommitDiff, CommitStatus, DeployKey, Discussion, Email, Epic, Event, FeatureFlag, GpgKey, Group, GroupAccessRequest, GroupBadge, GroupCluster, GroupHook, GroupLabel, GroupLink, GroupMilestone, ImpersonationToken, Issue, Job, Key, LabFile, License, Member, Membership, MergeApproval, MergeRequest, MergeRequestDiff, Namespace, Note, Pipeline, PipelineSchedule, Project, ProjectAccessRequest, ProjectBadge, ProjectCluster, ProjectDeployment, ProjectEnvironment, ProjectHook, ProjectLabel, ProjectMilestone, ProjectMirror, ProjectRelease, ProjectReleaseLink, ProjectService, ProjectSnippet, ProjectTrigger, ProjectVariable, ProtectedEnvironment, PushRule, RegistryRepository, RegistryTag, RepositoryTree, ResourceLabel, Runner, Snippet, SystemHook, Tag, TerraformState, Todo, User, Wiki
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Attributes inherited from LabStruct
Class Method Summary collapse
-
.date_time_attrs(list) ⇒ Object
Define a list of DateTime Attributes.
-
.user_attrs(list) ⇒ Object
Define a list of LabClient::User Attributes.
Instance Method Summary collapse
-
#api_methods ⇒ Object
Documented API Methods.
-
#collect_project_id(position = 1) ⇒ Object
(also: #collect_group_id, #collect_user_id)
TODO: Combine all of these?.
- #collect_release_id(position = 3) ⇒ Object
- #collect_repository_id(position = 4) ⇒ Object
-
#format_time?(time) ⇒ Boolean
Formatting Time Helper.
-
#group_name ⇒ Object
Category and Primary Key for docs.
-
#help(help_filter = nil) ⇒ Object
API Methods here have to be explicitly documented / custom helpers Assume no methods by default.
-
#initialize(table = nil, response = nil, client = nil) ⇒ Klass
constructor
A new instance of Klass.
-
#klass ⇒ Object
Helper to get docs.
-
#quiet? ⇒ Boolean
Quiet Reader Helper.
-
#success? ⇒ Boolean
Forward response success.
-
#to_json(*_args) ⇒ Object
Prevent stack level errors, but turning into has first.
- #update_self(obj) ⇒ Object
- #valid_group_project_levels ⇒ Object
-
#verbose ⇒ Object
TODO: Awesome Print / Amazing Print Conflicts?.
Methods included from Docs
demo, desc, doc, docs, example, json, markdown, navigation, option, result, subtitle, title
Methods included from CurlHelper
Methods included from Logger
Methods inherited from LabStruct
#[], #[]=, #as_json, #inspect, #key?, #keys, #method_missing, #respond_to_missing?, #slice, #to_h
Constructor Details
#initialize(table = nil, response = nil, client = nil) ⇒ Klass
Returns a new instance of Klass.
108 109 110 111 112 113 114 |
# File 'lib/labclient/klass.rb', line 108 def initialize(table = nil, response = nil, client = nil) # @table = table unless table.nil? @client = client @response = response super(table) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class LabClient::LabStruct
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/labclient/klass.rb', line 8 def client @client end |
Class Method Details
.date_time_attrs(list) ⇒ Object
Define a list of DateTime Attributes
127 128 129 130 131 132 133 |
# File 'lib/labclient/klass.rb', line 127 def self.date_time_attrs(list) list.each do |kind| define_method(kind) do DateTime.parse @table[kind] if has? kind end end end |
Instance Method Details
#api_methods ⇒ Object
Documented API Methods
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/labclient/klass.rb', line 43 def api_methods docs = LabClient::Docs.docs.dig(group_name, 'Reference') unless docs puts 'No Available Help' return false end LabClient::Docs.docs.dig(group_name, 'Reference').map do |doc| doc[:options].map do |opt| opt[:name] end end.flatten.sort end |
#collect_project_id(position = 1) ⇒ Object Also known as: collect_group_id, collect_user_id
TODO: Combine all of these?
63 64 65 66 67 68 69 70 |
# File 'lib/labclient/klass.rb', line 63 def collect_project_id(position = 1) # Check if Path / Pagination will be blank if response.path.nil? response.request.base_url.split(@client.base_url, 2)[position] else CGI.unescape response.path.split('/')[position] end end |
#collect_release_id(position = 3) ⇒ Object
75 76 77 |
# File 'lib/labclient/klass.rb', line 75 def collect_release_id(position = 3) response.path.split('/')[position] end |
#collect_repository_id(position = 4) ⇒ Object
79 80 81 |
# File 'lib/labclient/klass.rb', line 79 def collect_repository_id(position = 4) response.path.split('/')[position] end |
#format_time?(time) ⇒ Boolean
Formatting Time Helper
122 123 124 |
# File 'lib/labclient/klass.rb', line 122 def format_time?(time) time.respond_to?(:to_time) end |
#group_name ⇒ Object
Category and Primary Key for docs
84 85 86 |
# File 'lib/labclient/klass.rb', line 84 def group_name self.class.instance_variable_get('@group_name') || klass.pluralize end |
#help(help_filter = nil) ⇒ Object
API Methods here have to be explicitly documented / custom helpers Assume no methods by default
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/labclient/klass.rb', line 19 def help(help_filter = nil) docs = LabClient::Docs.docs.dig(group_name, 'Reference') unless docs puts 'No Available Help' return false end puts klass docs.each do |doc| next unless doc[:options] doc[:options].each do |opt| next if help_filter && !(opt[:name] + opt[:text]).include?(help_filter.to_s) puts " #{opt[:name]}" puts " #{opt[:text]}\n" end end # Ignore Output nil end |
#klass ⇒ Object
Helper to get docs
94 95 96 |
# File 'lib/labclient/klass.rb', line 94 def klass self.class.name.split('::', 2).last.split(/(?=[A-Z])/).join(' ') end |
#quiet? ⇒ Boolean
Quiet Reader Helper
104 105 106 |
# File 'lib/labclient/klass.rb', line 104 def quiet? client.quiet? end |
#success? ⇒ Boolean
Forward response success
117 118 119 |
# File 'lib/labclient/klass.rb', line 117 def success? @response.success? end |
#to_json(*_args) ⇒ Object
Prevent stack level errors, but turning into has first
89 90 91 |
# File 'lib/labclient/klass.rb', line 89 def to_json(*_args) to_h.to_json end |
#update_self(obj) ⇒ Object
98 99 100 101 |
# File 'lib/labclient/klass.rb', line 98 def update_self(obj) @table = obj.table self end |
#valid_group_project_levels ⇒ Object
58 59 60 |
# File 'lib/labclient/klass.rb', line 58 def valid_group_project_levels %i[guest reporter developer maintainer owner] end |
#verbose ⇒ Object
TODO: Awesome Print / Amazing Print Conflicts?
13 14 15 |
# File 'lib/labclient/klass.rb', line 13 def verbose ap @table, ruby19_syntax: true end |