class Cylons::Agent
this is the local application remote which is dynamically built, from the registry
Attributes
built[RW]
schema[RW]
errors[RW]
Public Class Methods
agent_namespace()
click to toggle source
# File lib/cylons/agent.rb, line 54 def self.agent_namespace @agent_namespace ||= ::Cylons::RemoteDiscovery.namespace_for_agent(self.name) end
all()
click to toggle source
# File lib/cylons/agent.rb, line 50 def self.all remote.all end
build_agent()
click to toggle source
# File lib/cylons/agent.rb, line 27 def self.build_agent load_schema @built = true end
count()
click to toggle source
# File lib/cylons/agent.rb, line 58 def self.count remote.count end
create(params)
click to toggle source
# File lib/cylons/agent.rb, line 74 def self.create(params) remote.create(params) end
find(id)
click to toggle source
# File lib/cylons/agent.rb, line 66 def self.find(id) remote.find(id) end
first()
click to toggle source
# File lib/cylons/agent.rb, line 62 def self.first remote.first end
first_or_create(params)
click to toggle source
# File lib/cylons/agent.rb, line 86 def self.first_or_create(params) result = remote.scope_by(params).first result = remote.create(params) unless result.present? result end
first_or_initialize(params)
click to toggle source
# File lib/cylons/agent.rb, line 92 def self.first_or_initialize(params) result = remote.scope_by(params).first result ||= remote.new(params) unless result.present? result end
inherited(subklass)
click to toggle source
# File lib/cylons/agent.rb, line 23 def self.inherited(subklass) ::Cylons.connect unless ::Cylons.connected? end
last()
click to toggle source
# File lib/cylons/agent.rb, line 70 def self.last remote.last end
load_schema()
click to toggle source
# File lib/cylons/agent.rb, line 36 def self.load_schema ::Cylons.logger.debug { "Loading schema for #{name}" } @schema = ::Cylons::RemoteRegistry.get_remote_schema(name.downcase) @schema.remote_attributes.each do |remote_attribute| attribute remote_attribute.to_sym end @schema.remote_associations.each do |association_hash| __send__("build_remote_#{association_hash[:association_type]}_association", association_hash) end end
remote()
click to toggle source
# File lib/cylons/agent.rb, line 98 def self.remote remote_connection_failed! unless remote? build_agent unless built ::DCell::Node[agent_namespace][service_class_name.to_sym] end
remote?()
click to toggle source
# File lib/cylons/agent.rb, line 106 def self.remote? agent_namespace && remote_application? && remote_service? end
remote_application?()
click to toggle source
# File lib/cylons/agent.rb, line 110 def self.remote_application? ::DCell::Node.all.any?{ |node| node.id == agent_namespace } end
remote_connection_failed!()
click to toggle source
# File lib/cylons/agent.rb, line 120 def self.remote_connection_failed! if self.unsucessful_remote_connection_attempts > ::Cylons.config.remote_connection_failure_threshold self.unsucessful_remote_connection_attempts = 0 raise ::Cylons::CylonsRemoteServiceNotFound, "#{service_class_name} not found" else sleep(::Cylons.config.remote_connection_failure_timeout) self.unsucessful_remote_connection_attempts += 1 remote_connection_failed! unless remote? end end
remote_service?()
click to toggle source
# File lib/cylons/agent.rb, line 116 def self.remote_service? ::DCell::Node[agent_namespace].actors.include?(service_class_name.to_sym) end
scope_by(params)
click to toggle source
# File lib/cylons/agent.rb, line 82 def self.scope_by(params) remote.scope_by(params) end
search(params)
click to toggle source
# File lib/cylons/agent.rb, line 78 def self.search(params) remote.search(params) end
service_class_name()
click to toggle source
# File lib/cylons/agent.rb, line 32 def self.service_class_name "#{name}Service" end
Public Instance Methods
destroy()
click to toggle source
# File lib/cylons/agent.rb, line 133 def destroy return unless self.attributes["id"] result = self.class.remote.destroy(self.attributes["id"]) end
save()
click to toggle source
have to manually update attributes if id wasnt set, i believe attr_accessible oddity so maybe can rip out later
# File lib/cylons/agent.rb, line 139 def save if self.attributes["id"] result = self.class.remote.save(self.attributes["id"], self.attributes.with_indifferent_access.slice(*self.changed)) self.changed_attributes.clear else result = self.class.remote.save(nil, self.attributes.with_indifferent_access.slice(*self.changed)) if result.errors.messages.present? self.assign_attributes({:errors => result.errors}) else self.assign_attributes(result.attributes) end end result end