Sha256: 8c92585a336165ffce5bd2d581ec4dabbebf7ec020341ba2af8e0c9863f00e02

Contents?: true

Size: 493 Bytes

Versions: 5

Compression:

Stored size: 493 Bytes

Contents

require "trailblazer/option"

module Representable
  # Extend `Trailblazer::Option` to support static values as callables too.
  class Option < ::Trailblazer::Option
    def self.callable?(value)
      [Proc, Symbol, Uber::Callable].any?{ |kind| value.is_a?(kind) }
    end

    def self.build(value)
      return ->(*) { value } unless callable?(value) # Wrap static `value` into a proc. 
      super
    end
  end

  def self.Option(value)
    ::Representable::Option.build(value)
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/representable-3.2.0/lib/representable/option.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/representable-3.2.0/lib/representable/option.rb
representable-3.2.0 lib/representable/option.rb
representable-3.1.1 lib/representable/option.rb
representable-3.1.0 lib/representable/option.rb