Sha256: 9a42bb1db6e5e8b0459995d325805097e9acc6393da639cc6e66a23552724107

Contents?: true

Size: 888 Bytes

Versions: 3

Compression:

Stored size: 888 Bytes

Contents

require 'representable'

module Roar
  module Representer
    # TODO: move to separate module
    # DISCUSS: experimental. this will soon be moved to a separate gem
    module InheritableArray
      def representable_attrs
        super.extend(ConfigExtensions)
      end

      module ConfigExtensions
        def inheritable_array(name)
          inheritable_arrays[name] ||= []
        end
        def inheritable_arrays
          @inheritable_arrays ||= {}
        end

        def inherit(parent)
          super
          
          parent.inheritable_arrays.keys.each do |k|
            inheritable_array(k).push *parent.inheritable_array(k).clone
          end
        end
      end
    end

    def self.included(base)
      base.class_eval do
        include Representable
      end
    end

    include InheritableArray

  private
    def before_serialize(*)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
roar-0.11.14 lib/roar/representer.rb
roar-0.11.13 lib/roar/representer.rb
roar-0.11.12 lib/roar/representer.rb