module Trellohub::Configurable
Public Class Methods
keys()
click to toggle source
# File lib/trellohub/configurable.rb, line 4 def keys %i( config_file board_id repositories lists options trello_application_key trello_application_token github_access_token github_api_endpoint github_web_endpoint dry_run debug ) end
overrideable_keys()
click to toggle source
# 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
Public Instance Methods
configurations()
click to toggle source
# File lib/trellohub/configurable.rb, line 100 def configurations Hash[Trellohub::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }] end
Also aliased as: conf
configure() { |self| ... }
click to toggle source
# File lib/trellohub/configurable.rb, line 37 def configure yield self end
default!()
click to toggle source
# File lib/trellohub/configurable.rb, line 41 def default! @config_file = ENV['CONFIG_FILE'] @repositories = [] @lists = [] @options = { 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()
click to toggle source
# File lib/trellohub/configurable.rb, line 125 def default_list Trellohub.list_by(default: true) end
dry_run=(bool)
click to toggle source
# File lib/trellohub/configurable.rb, line 162 def dry_run=(bool) @dry_run = bool Mocking.send(@dry_run ? :start : :stop) end
github_api_endpoint()
click to toggle source
# File lib/trellohub/configurable.rb, line 154 def github_api_endpoint File.join(@github_api_endpoint, '') end
github_web_endpoint()
click to toggle source
# File lib/trellohub/configurable.rb, line 158 def github_web_endpoint File.join(@github_web_endpoint, '') end
init!()
click to toggle source
# 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()
click to toggle source
# 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: [])
click to toggle source
# 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()
click to toggle source
# File lib/trellohub/configurable.rb, line 129 def list_names @lists.map(&:name).compact end
load!(config_file = nil)
click to toggle source
# 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!()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/trellohub/configurable.rb, line 146 def repository_full_names @repositories.map(&:full_names).compact end
repository_milestones()
click to toggle source
# File lib/trellohub/configurable.rb, line 150 def repository_milestones @repositories.map(&:milestone).uniq end
setup(config_file = nil)
click to toggle source
# File lib/trellohub/configurable.rb, line 92 def setup(config_file = nil) default! load!(config_file) override! init! self end