Sha256: 25a457d10bac730128e26cc48b98522a2f11fd68a6b563d0699795fdf315e111

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

module PhraseApp
  module InContextEditor
    class Config
      CONFIG_OPTIONS = {
        account_id: nil,
        project_id: nil,
        datacenter: "eu",
        enabled: false,
        backend: PhraseApp::InContextEditor::BackendService.new,
        prefix: "{{__",
        suffix: "__}}",
        origin: "in-context-editor-ruby",
        ignored_keys: []
      }.freeze

      CONFIG_OPTIONS.each do |option, default_value|
        class_eval "@@#{option} = CONFIG_OPTIONS[:#{option}]", __FILE__, __LINE__

        define_method("#{option}=") do |value|
          instance_eval "@#{option} = value", __FILE__, __LINE__
        end

        define_method(option.to_s) do
          instance_eval "defined?(@#{option}) ? @#{option} : self.class.#{option}", __FILE__, __LINE__
        end

        define_singleton_method("#{option}=") do |value|
          instance_eval "@@#{option} = value", __FILE__, __LINE__
        end

        define_singleton_method(option.to_s) do
          instance_eval "@@#{option}", __FILE__, __LINE__
        end
      end

      def assign_values(config_options = {})
        config_options.each do |config_option, value|
          send("#{config_option}=", value)
        end
      end

      def self.reset_to_defaults!
        CONFIG_OPTIONS.each do |option, default_value|
          send("#{option}=", default_value)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
phraseapp-in-context-editor-ruby-3.2.0 lib/phraseapp-in-context-editor-ruby/config.rb
phraseapp-in-context-editor-ruby-3.1.1 lib/phraseapp-in-context-editor-ruby/config.rb
phraseapp-in-context-editor-ruby-3.1.0 lib/phraseapp-in-context-editor-ruby/config.rb