I need to model an IP address and thought using a state machine (the state_machine gem) would be a good idea. An IP has the following characteristics:It is assigned to a server.It can be in state unbound (implies unprotected), bound (implies protected), reserved.It has several firewall rules which should be automatically activated/deactivated when binding/unbinding.It can be migrated from/to another server.All operations, such as (de)activating firewall rules and (un)binding, may fail or externally change their state (consider a machine reboot).Here is what I came up with so far:require 'rubygems'require 'state_machine'require 'awesome_print'class Ip  state_machine :state, :initial => :unbound do    # idle states, i.e. only an event (either external or internal) will trigger a transition.    state :unbound, :bound, :reserved    # transitionary states, we expect a state change after a certain period of time.    state :protected, :unprotected    event :cycle do      transition :unbound => :protected      transition :protected => :bound      transition :bound => :unprotected      transition :unprotected => :unbound    end    event :reserve do      transition :unbound => :reserved    end    event :release do      transition :reserved => :unbound    end    before_transition any => any, :if => :refreshing? do |ip, transition|      puts refreshing, before_transition -> state is: #{transition.from}, state will be: #{transition.to}      throw :halt unless ip.send(is_#{transition.to}?)    end    before_transition any => any do |ip, transition|      puts before_transition -> state is: #{transition.from}, state will be: #{transition.to}    end    before_transition any => :protected, :do => :activate_firewall_rules    before_transition any => :unprotected, :do => :deactivate_firewall_rules    before_transition any => :bound, :do => :bind_to_server    before_transition any => :unbound, :do => :unbind_from_server    after_transition any => any do |ip, transition|      puts after_transition -> state was: #{transition.from}, state is: #{transition.to}    end  end  def bind!    wait!(:bound)  end  def unbind!    wait!(:unbound)  end  def migrate!(new_server)    restore_state do      unbind!      self.server = new_server    end  end  def refresh!    return if reserved?    self.state = self.class.new.state # set to initial state    @refreshing = true    nil while cycle    @refreshing = false  end  def restore_state    old_state = state    yield    wait!(old_state)  end  def wait!(desired_state)    cycle! while !state?(desired_state)  end  def refreshing?    @refreshing  end  def activate_firewall_rules    puts activate_firewall_rules...    @is_protected = true  end  def deactivate_firewall_rules    puts deactivate_firewall_rules...    @is_protected = false  end  def bind_to_server    puts bind_to_server...    @is_bound = true  end  def unbind_from_server    puts unbind_from_server...    @is_bound = false  end  def is_protected?    puts is_protected: #{@is_protected}    @is_protected  end  def is_unprotected?    !is_protected?  end  def is_bound?    puts is_bound: #{@is_bound}    @is_bound  end  def is_unbound?    !is_bound?  endendThe public API should be something like this:bind! (bring up firewall and bind address to server)unbind! (unbind address to server and bring down firewallrefresh! (get real/external state and update internal state)migrate! (assign to new server, retain state)Since this is my very first state machine I thought I'd like to ask what you think about it. Do you think using a state machine makes sense here at all? Am I using it correctly or am I doing something wrong? What and why? 
Usage of state machine to model lifetime of an IP address
ruby;state