Class: LabClient::Klass
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- LabClient::Klass
- Extended by:
- Docs
- Includes:
- CurlHelper
- Defined in:
- lib/labclient/klass.rb
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, GpgKey, Group, GroupAccessRequest, GroupBadge, GroupHook, GroupLabel, GroupLink, GroupMilestone, ImpersonationToken, Issue, Job, Key, License, Member, MergeApproval, MergeRequest, MergeRequestDiff, Namespace, Note, Pipeline, PipelineSchedule, Project, ProjectAccessRequest, ProjectBadge, ProjectCluster, ProjectDeployment, ProjectEnvironment, ProjectHook, ProjectLabel, ProjectMilestone, ProjectMirror, ProjectRelease, ProjectReleaseLink, ProjectService, ProjectSnippet, ProjectTrigger, ProjectVariable, PushRule, RegistryRepository, RegistryTag, ResourceLabel, Runner, Snippet, SystemHook, Tag, Todo, User, Wiki
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
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
-
#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 ⇒ Object
API Methods here have to be explicitly documented / custom helpers Assume no methods by default.
-
#initialize(hash = nil, response = nil, client = nil) ⇒ Klass
constructor
A new instance of Klass.
-
#klass ⇒ Object
Helper to get docs.
-
#to_json(*_args) ⇒ Object
Prevent stack level errors, but turning into has first.
- #update_self(obj) ⇒ Object
- #valid_group_project_levels ⇒ Object
- #verbose ⇒ Object
Methods included from Docs
desc, doc, docs, example, json, markdown, navigation, option, result, subtitle, title
Methods included from CurlHelper
Methods inherited from OpenStruct
Constructor Details
#initialize(hash = nil, response = nil, client = nil) ⇒ Klass
Returns a new instance of Klass.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/labclient/klass.rb', line 77 def initialize(hash = nil, response = nil, client = nil) @client = client @response = response @table = {} hash&.each_pair do |k, v| k = k.to_sym @table[k] = v end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/labclient/klass.rb', line 7 def client @client end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/labclient/klass.rb', line 7 def response @response end |
Class Method Details
.date_time_attrs(list) ⇒ Object
Define a list of DateTime Attributes
94 95 96 97 98 99 100 |
# File 'lib/labclient/klass.rb', line 94 def self.date_time_attrs(list) list.each do |kind| define_method(kind) do DateTime.parse @table[kind] if has? kind end end end |
.user_attrs(list) ⇒ Object
Define a list of LabClient::User Attributes
103 104 105 106 107 108 109 |
# File 'lib/labclient/klass.rb', line 103 def self.user_attrs(list) list.each do |kind| define_method(kind) do User.new(@table[kind], response, client) if has? kind end end end |
Instance Method Details
#collect_project_id(position = 1) ⇒ Object Also known as: collect_group_id, collect_user_id
TODO: Combine all of these?
42 43 44 |
# File 'lib/labclient/klass.rb', line 42 def collect_project_id(position = 1) response.path.split('/')[position] end |
#collect_release_id(position = 3) ⇒ Object
49 50 51 |
# File 'lib/labclient/klass.rb', line 49 def collect_release_id(position = 3) response.path.split('/')[position] end |
#collect_repository_id(position = 4) ⇒ Object
53 54 55 |
# File 'lib/labclient/klass.rb', line 53 def collect_repository_id(position = 4) response.path.split('/')[position] end |
#format_time?(time) ⇒ Boolean
Formatting Time Helper
89 90 91 |
# File 'lib/labclient/klass.rb', line 89 def format_time?(time) time.respond_to?(:to_time) end |
#group_name ⇒ Object
Category and Primary Key for docs
58 59 60 |
# File 'lib/labclient/klass.rb', line 58 def group_name self.class.instance_variable_get('@group_name') || klass.pluralize end |
#help ⇒ Object
API Methods here have to be explicitly documented / custom helpers Assume no methods by default
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/labclient/klass.rb', line 16 def help 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| puts ' ' + opt[:name] puts " #{opt[:text]}\n" end end # Ignore Output nil end |
#klass ⇒ Object
Helper to get docs
68 69 70 |
# File 'lib/labclient/klass.rb', line 68 def klass self.class.name.split('::', 2).last.split(/(?=[A-Z])/).join(' ') end |
#to_json(*_args) ⇒ Object
Prevent stack level errors, but turning into has first
63 64 65 |
# File 'lib/labclient/klass.rb', line 63 def to_json(*_args) to_h.to_json end |
#update_self(obj) ⇒ Object
72 73 74 75 |
# File 'lib/labclient/klass.rb', line 72 def update_self(obj) @table = obj.table self end |
#valid_group_project_levels ⇒ Object
37 38 39 |
# File 'lib/labclient/klass.rb', line 37 def valid_group_project_levels i[guest reporter developer maintainer owner] end |
#verbose ⇒ Object
10 11 12 |
# File 'lib/labclient/klass.rb', line 10 def verbose ap self end |