Sha256: 866deae1fd8461977a9e8a47078c876664bb6056e4d56b8dfdec340f5bcc5cd5

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 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"
      }.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

2 entries across 2 versions & 1 rubygems

Version Path
phraseapp-in-context-editor-ruby-3.0.1 lib/phraseapp-in-context-editor-ruby/config.rb
phraseapp-in-context-editor-ruby-2.1.1 lib/phraseapp-in-context-editor-ruby/config.rb