Sha256: ba4640c4eeb6e8d3951c617be98dd6fe31e07804fae09e11eb0054384ac0f421

Contents?: true

Size: 1.98 KB

Versions: 4

Compression:

Stored size: 1.98 KB

Contents

module UltimateTurboModal
  class << self
    attr_accessor :configuration
  end

  def self.configure
    self.configuration ||= Configuration.new
    yield(configuration) if block_given?
  end

  delegate :flavor, :flavor=, :close_button, :close_button=,
    :advance, :advance=, :padding, :padding=, to: :configuration

  class Configuration
    attr_reader :flavor, :close_button, :advance, :padding, :header, :header_divider, :footer_divider

    def initialize
      @flavor = :tailwind
      @close_button = true
      @advance = true
      @padding = true
      @header = true
      @header_divider = true
      @footer_divider = true
    end

    def flavor=(flavor)
      raise ArgumentError.new("Value must be a symbol.") unless flavor.is_a?(Symbol) || flavor.is_a?(String)
      @flavor = flavor.to_sym
    end

    def close_button=(close_button)
      raise ArgumentError.new("Value must be a boolean.") unless [true, false].include?(close_button)
      @close_button = close_button
    end

    def advance=(advance)
      raise ArgumentError.new("Value must be a boolean.") unless [true, false].include?(advance)
      @advance = advance
    end

    def padding=(padding)
      if [true, false].include?(padding) || padding.is_a?(String)
        @padding = padding
      else
        raise ArgumentError.new("Value must be a boolean or a String.")
      end
    end

    def header=(header)
      raise ArgumentError.new("Value must be a boolean.") unless [true, false].include?(header)
      @header = header
    end

    def header_divider=(header_divider)
      raise ArgumentError.new("Value must be a boolean.") unless [true, false].include?(header_divider)
      @header_divider = header_divider
    end

    def footer_divider=(footer_divider)
      raise ArgumentError.new("Value must be a boolean.") unless [true, false].include?(footer_divider)
      @footer_divider = footer_divider
    end
  end
end

# Make sure the configuration object is set up when the gem is loaded.
UltimateTurboModal.configure

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ultimate_turbo_modal-1.3.1 lib/ultimate_turbo_modal/configuration.rb
ultimate_turbo_modal-1.3.0 lib/ultimate_turbo_modal/configuration.rb
ultimate_turbo_modal-1.2.1 lib/ultimate_turbo_modal/configuration.rb
ultimate_turbo_modal-1.2.0 lib/ultimate_turbo_modal/configuration.rb