Sha256: 26bddd3fa3a062800a87ceca141dbd29790a5d37664c90ccf27d69176d35b61f

Contents?: true

Size: 1.14 KB

Versions: 130

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Spree
  module DisplayMoney
    ##
    # Takes a list of methods that the base object wants to be able to use
    # to display with Spree::Money, and turns them into display_* methods.
    # Intended to help clean up some of the presentational logic that exists
    # at the model layer.
    #
    #
    # ==== Examples
    # Decorate a method, with the default option of using the base object's
    # currency
    #
    #     extend Spree::DisplayMoney
    #     money_methods :tax_amount, :price
    #
    # Decorate a method, but with some additional options
    #     extend Spree::DisplayMoney
    #     money_methods tax_amount: { currency: "CAD", no_cents: true }, :price
    def money_methods(*args)
      args.each do |money_method|
        money_method = { money_method => {} } unless money_method.is_a? Hash
        money_method.each do |method_name, opts|
          define_method("display_#{method_name}") do
            default_opts = respond_to?(:currency) ? { currency: currency } : {}
            Spree::Money.new(send(method_name), default_opts.merge(opts))
          end
        end
      end
    end
  end
end

Version data entries

130 entries across 130 versions & 2 rubygems

Version Path
solidus_core-4.3.4 app/models/concerns/spree/display_money.rb
solidus_core-4.2.4 app/models/concerns/spree/display_money.rb
solidus_core-4.1.5 app/models/concerns/spree/display_money.rb
solidus_core-4.3.3 app/models/concerns/spree/display_money.rb
solidus_core-4.3.2 app/models/concerns/spree/display_money.rb
solidus_core-4.1.4 app/models/concerns/spree/display_money.rb
solidus_core-4.3.1 app/models/concerns/spree/display_money.rb
solidus_core-4.3.0 app/models/concerns/spree/display_money.rb
solidus_core-4.2.3 app/models/concerns/spree/display_money.rb
solidus_core-4.1.3 app/models/concerns/spree/display_money.rb
solidus_core-4.0.4 app/models/concerns/spree/display_money.rb
solidus_core-3.4.6 app/models/concerns/spree/display_money.rb
solidus_core-4.0.3 app/models/concerns/spree/display_money.rb
solidus_core-4.1.2 app/models/concerns/spree/display_money.rb
solidus_core-4.2.2 app/models/concerns/spree/display_money.rb
solidus_core-3.4.5 app/models/concerns/spree/display_money.rb
solidus_core-4.2.1 app/models/concerns/spree/display_money.rb
solidus_core-4.2.0 app/models/concerns/spree/display_money.rb
solidus_core-4.1.1 app/models/concerns/spree/display_money.rb
solidus_core-4.0.2 app/models/concerns/spree/display_money.rb