Sha256: 5e0a63e972a31290aee0eb4913c6b0546ee86fca3b339ce2c594a84b1e968c5b

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Restfulie
  
  module Server

    # represents a transition on the server side
    class Transition
      attr_reader :body, :name, :result
      def initialize(name, options, result, body)
        @name = name
        @options = options
        @result = result
        @body = body
      end
      def action
        @options || {}
      end
      
      # executes this transition in a resource
      def execute_at(target_object)
        target_object.status = result.to_s unless result.nil?
      end
    
      # adds a link to this transition's uri on a xml writer
      def add_link_to(xml, model, options)
        specific_action = action.dup
        specific_action = @body.call(model) if @body

        rel = specific_action[:rel] || @name
        specific_action[:rel] = nil

        specific_action[:action] ||= @name
        uri = options[:controller].url_for(specific_action)
      
        if options[:use_name_based_link]
          xml.tag!(rel, uri)
        else
          xml.tag!('atom:link', 'xmlns:atom' => 'http://www.w3.org/2005/Atom', :rel => rel, :href => uri)
        end
      end
    
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
restfulie-0.3 lib/restfulie/server/transition.rb