Sha256: 850f91d2e570563750b2072c3408644d15db04798005aa7cf2c5f2247dd77a18

Contents?: true

Size: 678 Bytes

Versions: 21

Compression:

Stored size: 678 Bytes

Contents

require 'active_support/concern'

module HalApi::Representer::LinkSerialize

  extend ActiveSupport::Concern

  module ClassMethods

    def link(options, &block)
      set_link_property(options)
      super(options, &block)
    end

    def set_link_property(options)
      if options.is_a?(Hash) && (options.delete(:writeable) || options[:reader])
        name = options[:rel].to_s.split(':').last.split('/').last
        pname = "set_#{name}_uri"
        reader = options.delete(:reader) || ->(doc, _args) do
          try("#{name}_id=", id_from_url(doc[pname])) if doc[pname]
        end

        property(pname, readable: false, reader: reader)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hal_api-rails-0.3.7 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.3.6 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.3.5 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.7.0 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.6.0 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.5.0 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.4.1 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.4.0 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.3.4 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.3.3 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.3.2 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.3.1 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.3.0 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.2.9 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.2.8 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.2.7 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.2.6 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.2.5 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.2.4 lib/hal_api/representer/link_serialize.rb
hal_api-rails-0.2.3 lib/hal_api/representer/link_serialize.rb