Sha256: 96b61af1269670c55ee6a56574752c9de80f1358d5c954469206fd90c3294065

Contents?: true

Size: 1.16 KB

Versions: 33

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "react_on_rails/utils"

module ReactOnRails
  module ReactComponent
    class Options
      include Utils::Required

      NO_PROPS = {}.freeze

      def initialize(name: required("name"), options: required("options"))
        @name = name
        @options = options
      end

      def props
        options.fetch(:props) { NO_PROPS }
      end

      def name
        @name.camelize
      end

      def dom_id
        @dom_id ||= options.fetch(:id) { generate_unique_dom_id }
      end

      def html_options
        options[:html_options].to_h
      end

      def prerender
        retrieve_key(:prerender)
      end

      def trace
        retrieve_key(:trace)
      end

      def replay_console
        retrieve_key(:replay_console)
      end

      def raise_on_prerender_error
        retrieve_key(:raise_on_prerender_error)
      end

      private

      attr_reader :options

      def generate_unique_dom_id
        "#{@name}-react-component-#{SecureRandom.uuid}"
      end

      def retrieve_key(key)
        options.fetch(key) do
          ReactOnRails.configuration.public_send(key)
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
react_on_rails-11.0.0 lib/react_on_rails/react_component/options.rb
react_on_rails-11.0.0.beta.1 lib/react_on_rails/react_component/options.rb
react_on_rails-10.1.4 lib/react_on_rails/react_component/options.rb
react_on_rails-10.1.3 lib/react_on_rails/react_component/options.rb
react_on_rails-10.1.1 lib/react_on_rails/react_component/options.rb
react_on_rails-10.1.0 lib/react_on_rails/react_component/options.rb
react_on_rails-10.0.2 lib/react_on_rails/react_component/options.rb
react_on_rails-10.0.1 lib/react_on_rails/react_component/options.rb
react_on_rails-10.0.0 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.3 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.2 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.1 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.0 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.0.rc.0 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.0.beta.12 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.0.beta.11 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.0.beta.10 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.0.beta.9 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.0.beta.8 lib/react_on_rails/react_component/options.rb
react_on_rails-9.0.0.beta.7 lib/react_on_rails/react_component/options.rb