Sha256: 739c53cc86f284d333db63b3c63e48fc0d495d6ec96387938747847f0deef1ff

Contents?: true

Size: 978 Bytes

Versions: 2

Compression:

Stored size: 978 Bytes

Contents

module Gorillib
  module Model

    #
    # give each field the next position in order
    #
    # @example
    #   class Foo
    #     include Gorillib::Model
    #     field :bob,    String               # not positional
    #     field :zoe,    String, position: 0  # positional 0 (explicit)
    #   end
    #   class Subby < Foo
    #     include Gorillib::Model::PositionalFields
    #     field :wun, String                  # positional 1
    #   end
    #   Foo.field    :nope, String            # not positional
    #   Subby.field  :toofer, String          # positional 2
    #
    # @note: make sure you're keeping positionals straight in super classes, or
    # in anything added after this.
    #
    module PositionalFields
      extend ActiveSupport::Concern

      module ClassMethods
        def field(*args)
          options = args.extract_options!
          super(*args, {position: positionals.count}.merge(options))
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gorillib-model-0.0.3 lib/gorillib/model/positional_fields.rb
gorillib-model-0.0.1 lib/gorillib/model/positional_fields.rb