Sha256: 16c880e086e3fe6df88fba9eab68c2537ea03e0d883003dc75ae4c62c53ae60c

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# iterates following a series of steps provided a goal and a starting uri.
#
# Restfulie::Client::Mikyung.achieve(objective).at(uri).run
#
# In order to implement your own walker, supply an object that respond to the move method.
# Check the run method code.
class Restfulie::Client::Mikyung::Core
  
  attr_reader :start, :goal, :walker
  
  def initialize
    @walker = Restfulie::Client::Mikyung::SteadyStateWalker.new
  end
  
  def walks_with(walker)
    @walker = walker
    self
  end

  # initializes with a goal in mind
  def achieve(goal)
    @goal = goal
    self
  end
  
  def at(start)
    @start = start
    self
  end

  # keeps changing from a steady state to another until its goal has been achieved
  def run
    @start = current = (@start.kind_of? String) ? Restfulie.at(@start).get : @start
    
    while(!@goal.completed?(current))
      current = @walker.move(@goal, current, self)
    end
    current
  end
  
end

class Restfulie::Client::UnableToAchieveGoalError < Restfulie::Common::Error::RestfulieError
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
restfulie-0.8.0 lib/restfulie/client/mikyung/core.rb