Class: PlanMyStuff::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/plan_my_stuff/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/plan_my_stuff/configuration.rb', line 93

def initialize
  @repos = {}
  @user_class = 'User'
  @display_name_method = :to_s
  @user_id_method = :id
  @support_method = :support?
  @markdown_renderer = :commonmarker
  @markdown_options = {}
  @job_classes = {}
  @custom_fields = {}
end

Instance Attribute Details

#access_tokenString

Returns GitHub PAT with repo and project scopes. Required.

Returns:

  • (String)

    GitHub PAT with repo and project scopes. Required.



6
7
8
# File 'lib/plan_my_stuff/configuration.rb', line 6

def access_token
  @access_token
end

#app_nameString?

Returns name of the consuming app, stored in metadata (e.g. “Atlas”).

Returns:

  • (String, nil)

    name of the consuming app, stored in metadata (e.g. “Atlas”)



84
85
86
# File 'lib/plan_my_stuff/configuration.rb', line 84

def app_name
  @app_name
end

#custom_fieldsHash{Symbol => Hash}

App-defined field definitions stored in issue/comment metadata. Keys are field names, values are hashes with :type and :required.

Returns:

  • (Hash{Symbol => Hash})


78
79
80
# File 'lib/plan_my_stuff/configuration.rb', line 78

def custom_fields
  @custom_fields
end

#default_project_numberInteger?

Returns default GitHub Projects V2 number for add_to_project calls.

Returns:

  • (Integer, nil)

    default GitHub Projects V2 number for add_to_project calls



15
16
17
# File 'lib/plan_my_stuff/configuration.rb', line 15

def default_project_number
  @default_project_number
end

#default_repoSymbol?

Returns default repo key used when callers omit repo: param.

Returns:

  • (Symbol, nil)

    default repo key used when callers omit repo: param



12
13
14
# File 'lib/plan_my_stuff/configuration.rb', line 12

def default_repo
  @default_repo
end

#deferred_email_fromString?

Returns sender address for built-in deferred request notifications.

Returns:

  • (String, nil)

    sender address for built-in deferred request notifications



68
69
70
# File 'lib/plan_my_stuff/configuration.rb', line 68

def deferred_email_from
  @deferred_email_from
end

#deferred_email_toString?

Returns recipient address for built-in deferred request notifications.

Returns:

  • (String, nil)

    recipient address for built-in deferred request notifications



71
72
73
# File 'lib/plan_my_stuff/configuration.rb', line 71

def deferred_email_to
  @deferred_email_to
end

#deferred_notifierProc?

Returns custom notifier for deferred requests, or nil to use DeferredMailer.

Returns:

  • (Proc, nil)

    custom notifier for deferred requests, or nil to use DeferredMailer



65
66
67
# File 'lib/plan_my_stuff/configuration.rb', line 65

def deferred_notifier
  @deferred_notifier
end

#display_name_methodSymbol

Returns method called on user object to get display name for comment headers.

Returns:

  • (Symbol)

    method called on user object to get display name for comment headers



21
22
23
# File 'lib/plan_my_stuff/configuration.rb', line 21

def display_name_method
  @display_name_method
end

#issues_url_prefixString?

Returns URL prefix for building user-facing ticket URLs in the consuming app.

Returns:

  • (String, nil)

    URL prefix for building user-facing ticket URLs in the consuming app



81
82
83
# File 'lib/plan_my_stuff/configuration.rb', line 81

def issues_url_prefix
  @issues_url_prefix
end

#job_classesHash{Symbol => String}

Map of action type to job class name for deferred requests. Keys: :create_ticket, :post_comment, :update_status.

Returns:

  • (Hash{Symbol => String})


62
63
64
# File 'lib/plan_my_stuff/configuration.rb', line 62

def job_classes
  @job_classes
end

#markdown_optionsHash

Default options passed to the markdown renderer. Per-call options in Markdown.render merge on top of these.

For :commonmarker - passed as ‘options:` to `Commonmarker.to_html`

e.g. `{ render: { hardbreaks: true } }`

For :redcarpet - :render_options and :renderer are extracted for the HTML renderer;

remaining keys are passed as extensions to `Redcarpet::Markdown.new`
e.g. `{ render_options: { hard_wrap: true, no_styles: true }, autolink: true }`

Returns:

  • (Hash)


48
49
50
# File 'lib/plan_my_stuff/configuration.rb', line 48

def markdown_options
  @markdown_options
end

#markdown_rendererSymbol

Returns which markdown gem to use: :commonmarker or :redcarpet.

Returns:

  • (Symbol)

    which markdown gem to use: :commonmarker or :redcarpet



34
35
36
# File 'lib/plan_my_stuff/configuration.rb', line 34

def markdown_renderer
  @markdown_renderer
end

#organizationString

Returns GitHub organization name. Required.

Returns:

  • (String)

    GitHub organization name. Required.



9
10
11
# File 'lib/plan_my_stuff/configuration.rb', line 9

def organization
  @organization
end

#reposHash{Symbol => String} (readonly)

Named repo configs. Set via config.repos = ‘BrandsInsurance/Element’.

Returns:

  • (Hash{Symbol => String})


90
91
92
# File 'lib/plan_my_stuff/configuration.rb', line 90

def repos
  @repos
end

#should_send_requestProc?

Proc returning boolean, or nil (always send). When it returns false the request is deferred to a background job instead of hitting GitHub.

Returns:

  • (Proc, nil)


55
56
57
# File 'lib/plan_my_stuff/configuration.rb', line 55

def should_send_request
  @should_send_request
end

#support_methodSymbol, Proc

Determines if a user is support staff. Symbol (method name on user) or Proc that receives the user object and returns boolean.

Returns:

  • (Symbol, Proc)


31
32
33
# File 'lib/plan_my_stuff/configuration.rb', line 31

def support_method
  @support_method
end

#user_classString

Returns consuming app’s user model class name, constantized for lookups.

Returns:

  • (String)

    consuming app’s user model class name, constantized for lookups



18
19
20
# File 'lib/plan_my_stuff/configuration.rb', line 18

def user_class
  @user_class
end

#user_id_methodSymbol

Returns method called on user object to extract the app-side user ID.

Returns:

  • (Symbol)

    method called on user object to extract the app-side user ID



24
25
26
# File 'lib/plan_my_stuff/configuration.rb', line 24

def user_id_method
  @user_id_method
end

Instance Method Details

#authenticate_with(&block) ⇒ void

This method returns an undefined value.

Sets the authentication block for engine controllers.



109
110
111
112
113
114
115
# File 'lib/plan_my_stuff/configuration.rb', line 109

def authenticate_with(&block)
  if block
    @authenticate_with = block
  else
    @authenticate_with
  end
end

#validate!void

This method returns an undefined value.

Validates that required configuration options are set.

Raises:



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/plan_my_stuff/configuration.rb', line 123

def validate!
  missing = []
  missing << 'access_token' if access_token.nil? || access_token.to_s.strip.empty?
  missing << 'organization' if organization.nil? || organization.to_s.strip.empty?

  return if missing.empty?

  raise(
    ConfigurationError,
    "Missing required PlanMyStuff configuration: #{missing.join(', ')}",
  )
end