Sha256: 285fb3e6e1234c8a78a6cf09b078c44a362deda114480ae552eae70555ba5032

Contents?: true

Size: 920 Bytes

Versions: 1

Compression:

Stored size: 920 Bytes

Contents

module Praxis
  class MediaType < Praxis::Blueprint
    include Types::MediaTypeCommon

    class DSLCompiler < Attributor::DSLCompiler
      def links(&block)
        attribute :links, Praxis::Links.for(options[:reference]), dsl_compiler: Links::DSLCompiler, &block
      end
    end

    def self.attributes(opts={}, &block)
      super(opts.merge(dsl_compiler: MediaType::DSLCompiler), &block)
    end

    def self._finalize!
      super
      if @attribute && self.attributes.key?(:links) && self.attributes[:links].type < Praxis::Links
        # Only define out special links accessor if it was setup using the special DSL
        # (we might have an app defining an attribute called `links` on its own, in which
        # case we leave it be)
        module_eval <<-RUBY, __FILE__, __LINE__ + 1
        def links
          self.class::Links.new(@object)
        end
        RUBY
      end
    end
    
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
praxis-0.14.0 lib/praxis/media_type.rb