Sha256: 9f4cd948bd11339701202e02353e3564380d317e7d864fbe9d5279bdc9ab0438

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'fathom'))
class Fathom::Agent

  # =================
  # = Class Methods =
  # =================
  class << self
    def define_node_accessor(name, node)
      method_name = ("node_for_" + name.to_s.downcase.gsub(/\s+/, '_')).to_sym
      define_method(method_name) do
        node
      end
    end
  end
  
  include Properties
  
  def initialize(opts={})
    self.class.define_property_states
    assert_node_accessors(opts)
  end
  
  def states
    @states ||= self.class.properties.inject({}) do |h, state_method_name|
      h[state_method_name] = nil
      h
    end
  end
  
  def callbacks
    @callbacks ||= (self.methods - Object.methods).grep(/^on_(\w+)/)
  end
  
  protected
    def assert_node_accessors(nodes)
      nodes.each do |name, node|
        next unless self.class.properties.include?(name)
        states[name] = node.respond_to?(:rand) ? node.rand : node
        self.class.define_node_accessor(name, node)
      end
    end
  
end

if __FILE__ == $0
  include Fathom
  # TODO: Is there anything you want to do to run this file on its own?
  # Agent.new
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fathom-0.3.0 lib/fathom/agent.rb
fathom-0.2.3 lib/fathom/agent.rb
fathom-0.2.2 lib/fathom/agent.rb
fathom-0.2.1 lib/fathom/agent.rb
fathom-0.2.0 lib/fathom/agent.rb