Sha256: 23477a14ee2f316ab8780863deff94941cc8543723e8c92a167f2b84f4d6ed35

Contents?: true

Size: 941 Bytes

Versions: 15

Compression:

Stored size: 941 Bytes

Contents

module Enumerable
  Groupdate::PERIODS.each do |period|
    define_method :"group_by_#{period}" do |*args, **options, &block|
      if block
        raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0)" if args.any?
        Groupdate::Magic::Enumerable.group_by(self, period, options, &block)
      elsif respond_to?(:scoping)
        scoping { @klass.group_by_period(period, *args, **options, &block) }
      else
        raise ArgumentError, "no block given"
      end
    end
  end

  def group_by_period(period, *args, **options, &block)
    if block || !respond_to?(:scoping)
      raise ArgumentError, "wrong number of arguments (given #{args.size + 1}, expected 1)" if args.any?

      Groupdate::Magic.validate_period(period, options.delete(:permit))
      send("group_by_#{period}", **options, &block)
    else
      scoping { @klass.group_by_period(period, *args, **options, &block) }
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
groupdate-6.4.0 lib/groupdate/enumerable.rb
groupdate-6.3.0 lib/groupdate/enumerable.rb
groupdate-6.2.1 lib/groupdate/enumerable.rb
groupdate-6.2.0 lib/groupdate/enumerable.rb
groupdate-6.1.0 lib/groupdate/enumerable.rb
groupdate-6.0.1 lib/groupdate/enumerable.rb
groupdate-6.0.0 lib/groupdate/enumerable.rb
groupdate-5.2.4 lib/groupdate/enumerable.rb
groupdate-5.2.3 lib/groupdate/enumerable.rb
groupdate-5.2.2 lib/groupdate/enumerable.rb
groupdate-5.2.1 lib/groupdate/enumerable.rb
groupdate-5.2.0 lib/groupdate/enumerable.rb
groupdate-5.1.0 lib/groupdate/enumerable.rb
groupdate2-5.0.0 lib/groupdate/enumerable.rb
groupdate-5.0.0 lib/groupdate/enumerable.rb