Sha256: 1a0c765eee52d21645a19cab39b9e5205041124c5bf29df3e6bf22f60899d750

Contents?: true

Size: 865 Bytes

Versions: 3

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

#
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Bumblebee
  # Defines a class-level interace for specifying columns.
  module ColumnDsl
    extend Forwardable

    def_delegators :column_set, :columns

    def column_set
      @column_set ||= ColumnSet.new
    end

    def column(header, opts = {})
      column_set.column(header, opts)

      self
    end

    def all_column_sets
      # the reverse preserves the order of inheritance to go from parent -> child
      ancestors.reverse_each.with_object(ColumnSet.new) do |ancestor, set|
        ancestor < Template ? set.add(ancestor.columns) : set
      end
    end

    def all_columns
      all_column_sets.columns
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bumblebee-3.1.1 lib/bumblebee/column_dsl.rb
bumblebee-3.1.0 lib/bumblebee/column_dsl.rb
bumblebee-3.1.0.pre.alpha lib/bumblebee/column_dsl.rb