Sha256: a956e220b0b49940f3ebff17a9158529ec5e32828204058220558632e6e6dde3

Contents?: true

Size: 1.04 KB

Versions: 15

Compression:

Stored size: 1.04 KB

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
        extend InheritableArray # this adds InheritableArray::representable_attrs to the module, e.g. when a representer includes a  representer, we don't work with the instance method, yet.
      end
    end

    include InheritableArray


  private
    def before_serialize(*)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
roar-0.12.9 lib/roar/representer.rb
roar-0.12.8 lib/roar/representer.rb
roar-0.12.7 lib/roar/representer.rb
roar-0.12.6 lib/roar/representer.rb
roar-0.12.5 lib/roar/representer.rb
roar-0.12.4 lib/roar/representer.rb
roar-0.12.3 lib/roar/representer.rb
roar-0.12.2 lib/roar/representer.rb
roar-0.12.1 lib/roar/representer.rb
roar-0.12.0 lib/roar/representer.rb
roar-0.11.19 lib/roar/representer.rb
roar-0.11.18 lib/roar/representer.rb
roar-0.11.17 lib/roar/representer.rb
roar-0.11.16 lib/roar/representer.rb
roar-0.11.15 lib/roar/representer.rb