Sha256: 6b3da9f79f4b36cd555f7876bbf4d8d7f16ff585d98896cfa3cfd0efcb70526f
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
# # Services::Entity: # This is the generic 'entity' for anything you want to attach to a service. # Inherit this for any other type a service may have. module Services require_relative '../services' # entity base class. # member,service,endpoint are all "services::entity" class Entity attr_reader :name, :path def initialize(name, _args = {}) @name = name validate end def store _store end alias_method :save, :store def load _load end def to_hash vars = {} instance_variables.each do |name| key = name[1..-1].to_s # don't store "path" next if key == 'path' vars[key] = instance_variable_get(name).to_s end vars end private def validate fail 'This class should be extended. Not used directly' unless path end def _store to_hash.each do |k, v| next if k == 'name' # etcd doesn't like nil v ||= '' Services.set "#{KEY}/#{path}/#{k}", value: v end end def _load return unless valid_path to_hash.each do |k, _v| next if k == 'name' next unless Services.exists? "#{KEY}/#{path}/#{k}" value = Services.get("#{KEY}/#{path}/#{k}").value Etcd::Log.debug "Got #{value} from #{KEY}/#{path}/#{k}" instance_variable_set "@#{k}", value end self end def valid_path Services.exists?("#{KEY}/#{path}") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jn_services-1.0.8 | lib/services/entity.rb |