Module: Trellohub::Configurable
- Included in:
- Trellohub
- Defined in:
- lib/trellohub/configurable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #configurations ⇒ Object (also: #conf)
- #configure {|_self| ... } ⇒ Object
- #default! ⇒ Object
- #default_list ⇒ Object
- #dry_run=(bool) ⇒ Object
- #github_api_endpoint ⇒ Object
- #github_web_endpoint ⇒ Object
- #init! ⇒ Object
- #issue_labels ⇒ Object
- #list_by(name: nil, default: nil, label: nil, labels: []) ⇒ Object
- #list_names ⇒ Object
- #load!(config_file = nil) ⇒ Object
- #override! ⇒ Object
- #repository_by(full_name: nil, milestone: nil) ⇒ Object
- #repository_full_names ⇒ Object
- #repository_milestones ⇒ Object
- #setup(config_file = nil) ⇒ Object
Class Method Details
.keys ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/trellohub/configurable.rb', line 4 def keys i( config_file board_id repositories lists trello_application_key trello_application_token github_access_token github_api_endpoint github_web_endpoint dry_run debug ) end |
.overrideable_keys ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/trellohub/configurable.rb', line 21 def overrideable_keys i( board_id trello_application_key trello_application_token github_access_token github_api_endpoint github_web_endpoint dry_run debug ) end |
Instance Method Details
#configurations ⇒ Object Also known as: conf
100 101 102 103 104 |
# File 'lib/trellohub/configurable.rb', line 100 def configurations Hash[Trellohub::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }] end |
#configure {|_self| ... } ⇒ Object
37 38 39 |
# File 'lib/trellohub/configurable.rb', line 37 def configure yield self end |
#default! ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/trellohub/configurable.rb', line 41 def default! @config_file = ENV['CONFIG_FILE'] @repositories = [] @lists = [] = { default_assignee: true, default_member: true } @github_api_endpoint = Octokit.api_endpoint @github_web_endpoint = Octokit.web_endpoint @dry_run = false @debug = true end |
#default_list ⇒ Object
125 126 127 |
# File 'lib/trellohub/configurable.rb', line 125 def default_list Trellohub.list_by(default: true) end |
#dry_run=(bool) ⇒ Object
162 163 164 165 |
# File 'lib/trellohub/configurable.rb', line 162 def dry_run=(bool) @dry_run = bool Mocking.send(@dry_run ? :start : :stop) end |
#github_api_endpoint ⇒ Object
154 155 156 |
# File 'lib/trellohub/configurable.rb', line 154 def github_api_endpoint File.join(@github_api_endpoint, '') end |
#github_web_endpoint ⇒ Object
158 159 160 |
# File 'lib/trellohub/configurable.rb', line 158 def github_web_endpoint File.join(@github_web_endpoint, '') end |
#init! ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/trellohub/configurable.rb', line 76 def init! Trell.configure do |c| c.application_key = @trello_application_key c.application_token = @trello_application_token end Octokit.configure do |c| c.access_token = @github_access_token c.api_endpoint = @github_api_endpoint c.web_endpoint = @github_web_endpoint c.auto_paginate = true end self.dry_run = true if @dry_run end |
#issue_labels ⇒ Object
133 134 135 |
# File 'lib/trellohub/configurable.rb', line 133 def issue_labels @lists.map(&:issue_label).compact end |
#list_by(name: nil, default: nil, label: nil, labels: []) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/trellohub/configurable.rb', line 107 def list_by(name: nil, default: nil, label: nil, labels: []) case when name @lists.find { |list| list.name == name } when default @lists.find { |list| list.default == true } when label @lists.find { |list| list.issue_label == label } else labels.each { |label_name| list = Trellohub.list_by(label: label_name) return list if list } unless labels.empty? Trellohub.default_list end end |
#list_names ⇒ Object
129 130 131 |
# File 'lib/trellohub/configurable.rb', line 129 def list_names @lists.map(&:name).compact end |
#load!(config_file = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/trellohub/configurable.rb', line 52 def load!(config_file = nil) config_file ||= @config_file YAML.load_file(config_file). symbolize_keys. slice(*Trellohub::Configurable.keys). each do |key, value| case key when :repositories value = value.map { |v| Trellohub::Repository.new(v) } when :lists value = value.map { |v| Trellohub::List.new(v) } end instance_variable_set(:"@#{key}", value) end end |
#override! ⇒ Object
69 70 71 72 73 74 |
# File 'lib/trellohub/configurable.rb', line 69 def override! Trellohub::Configurable.overrideable_keys.each do |key| env_name = key.to_s.upcase instance_variable_set(:"@#{key}", ENV[env_name]) if ENV[env_name] end end |
#repository_by(full_name: nil, milestone: nil) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/trellohub/configurable.rb', line 137 def repository_by(full_name: nil, milestone: nil) case when full_name @repositories.find { |repo| repo.full_name == full_name } when milestone @repositories.find { |repo| repo.milestone == milestone } end end |
#repository_full_names ⇒ Object
146 147 148 |
# File 'lib/trellohub/configurable.rb', line 146 def repository_full_names @repositories.map(&:full_names).compact end |
#repository_milestones ⇒ Object
150 151 152 |
# File 'lib/trellohub/configurable.rb', line 150 def repository_milestones @repositories.map(&:milestone).uniq end |
#setup(config_file = nil) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/trellohub/configurable.rb', line 92 def setup(config_file = nil) default! load!(config_file) override! init! self end |