Class: Koi::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/koi/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/koi/config.rb', line 21

def initialize
  @action_text_editor           = nil
  @admin_name                   = "Koi"
  @authenticate_local_admins    = Rails.env.development?
  @resource_name_candidates     = %i[title name]
  @admin_stylesheet             = "admin"
  @admin_javascript_entry_point = "@katalyst/koi"
  @document_mime_types          = %w[image/png image/gif image/jpeg image/webp application/pdf audio/*].freeze
  @document_size_limit          = 10.megabytes
  @image_mime_types             = %w[image/png image/gif image/jpeg image/webp].freeze
  @image_size_limit             = 10.megabytes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object (private)

rubocop:disable Style/MissingRespondToMissing

Raises:

  • (ArgumentError)


58
59
60
61
62
# File 'lib/koi/config.rb', line 58

def method_missing(name, *) # rubocop:disable Style/MissingRespondToMissing
  return super unless name.to_s.end_with?("=")

  raise ArgumentError, "Unknown Koi config setting: #{name.to_s.chomp('=')}"
end

Instance Attribute Details

#action_text_editorObject

Returns the value of attribute action_text_editor.



9
10
11
# File 'lib/koi/config.rb', line 9

def action_text_editor
  @action_text_editor
end

#admin_javascript_entry_pointObject

Returns the value of attribute admin_javascript_entry_point.



9
10
11
# File 'lib/koi/config.rb', line 9

def admin_javascript_entry_point
  @admin_javascript_entry_point
end

#admin_nameObject

Returns the value of attribute admin_name.



9
10
11
# File 'lib/koi/config.rb', line 9

def admin_name
  @admin_name
end

#admin_stylesheetObject

Returns the value of attribute admin_stylesheet.



9
10
11
# File 'lib/koi/config.rb', line 9

def admin_stylesheet
  @admin_stylesheet
end

#authenticate_local_adminsObject

Returns the value of attribute authenticate_local_admins.



9
10
11
# File 'lib/koi/config.rb', line 9

def authenticate_local_admins
  @authenticate_local_admins
end

#document_mime_typesObject

Returns the value of attribute document_mime_types.



9
10
11
# File 'lib/koi/config.rb', line 9

def document_mime_types
  @document_mime_types
end

#document_size_limitObject

Returns the value of attribute document_size_limit.



9
10
11
# File 'lib/koi/config.rb', line 9

def document_size_limit
  @document_size_limit
end

#image_mime_typesObject

Returns the value of attribute image_mime_types.



9
10
11
# File 'lib/koi/config.rb', line 9

def image_mime_types
  @image_mime_types
end

#image_size_limitObject

Returns the value of attribute image_size_limit.



9
10
11
# File 'lib/koi/config.rb', line 9

def image_size_limit
  @image_size_limit
end

#resource_name_candidatesObject

Returns the value of attribute resource_name_candidates.



9
10
11
# File 'lib/koi/config.rb', line 9

def resource_name_candidates
  @resource_name_candidates
end

#site_nameObject

Returns the value of attribute site_name.



9
10
11
# File 'lib/koi/config.rb', line 9

def site_name
  @site_name
end

Instance Method Details

#identityObject

Identity & access settings for OIDC authentication.



35
36
37
# File 'lib/koi/config.rb', line 35

def identity
  @identity ||= ActiveSupport::OrderedOptions.new.merge!(providers: {}, members: {})
end

#identity=(options) ⇒ Object



39
40
41
# File 'lib/koi/config.rb', line 39

def identity=(options)
  identity.deep_merge!(options.to_h)
end

#load(app) ⇒ Object

Load config/koi.yml, if present



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/koi/config.rb', line 44

def load(app)
  app.config_for(:koi).each do |attribute, value|
    public_send("#{attribute}=", value)
  end

  self
rescue RuntimeError => e
  raise unless e.message.start_with?("Could not load configuration")

  self
end