Sha256: 50180c9054ddfd8f7e97b5ed6d81e10f46dcc7d65086f323dc3449a9220532e1

Contents?: true

Size: 1.42 KB

Versions: 15

Compression:

Stored size: 1.42 KB

Contents

require "representable/decorator"
# require "representable/hash"

module Disposable
  class Twin
    class Decorator < Representable::Decorator
      # Overrides representable's Definition class so we can add semantics in our representers.
      class Definition < Representable::Definition
        def dynamic_options
          super + [:twin]
        end

        def twin_class
          self[:twin].evaluate(nil) # FIXME: do we support the :twin option, and should it be wrapped?
        end
      end

      # FIXME: this is not properly used when inheriting - fix that in representable.
      def self.build_config
        Config.new(Definition)
      end

      def self.each(options={})
        return representable_attrs[:definitions].values unless block_given?

        definitions = representable_attrs

        definitions.each do |dfn|
          next if options[:exclude]    and options[:exclude].include?(dfn.name)
          next if options[:scalar]     and dfn[:collection]
          next if options[:collection] and ! dfn[:collection]
          next if options[:twin]       and ! dfn[:twin]

          yield dfn
        end

        definitions
      end

      def self.default_inline_class
        Twin
      end


      class Options < ::Hash
        def exclude!(names)
          excludes.push(*names)
          self
        end

        def excludes
          self[:exclude] ||= []
        end
      end
    end # Decorator.
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
disposable-0.1.15 lib/disposable/twin/representer.rb
disposable-0.1.14 lib/disposable/twin/representer.rb
disposable-0.1.13 lib/disposable/twin/representer.rb
disposable-0.1.12 lib/disposable/twin/representer.rb
disposable-0.1.11 lib/disposable/twin/representer.rb
disposable-0.1.9 lib/disposable/twin/representer.rb
disposable-0.1.8 lib/disposable/twin/representer.rb
disposable-0.1.7 lib/disposable/twin/representer.rb
disposable-0.1.6 lib/disposable/twin/representer.rb
disposable-0.1.5 lib/disposable/twin/representer.rb
disposable-0.1.4 lib/disposable/twin/representer.rb
disposable-0.1.3 lib/disposable/twin/representer.rb
disposable-0.1.2 lib/disposable/twin/representer.rb
disposable-0.1.1 lib/disposable/twin/representer.rb
disposable-0.1.0 lib/disposable/twin/representer.rb