Class: Riddl::Utils::Notifications::Producer::Backend::Subs
- Inherits:
-
Object
- Object
- Riddl::Utils::Notifications::Producer::Backend::Subs
- Defined in:
- lib/ruby/riddl/utils/notifications_producer.rb
Overview
}}}
Instance Method Summary collapse
- #[](key) ⇒ Object
- #create(&block) ⇒ Object
- #each(&block) ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize(target) ⇒ Subs
constructor
{{{.
- #keys ⇒ Object
Constructor Details
#initialize(target) ⇒ Subs
{{{
83 84 85 |
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 83 def initialize(target) @target = target end |
Instance Method Details
#[](key) ⇒ Object
99 100 101 102 |
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 99 def [](key) f = @target + '/' + key + '/subscription.xml' File.exists?(f) ? Sub.new(f) : nil end |
#create(&block) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 104 def create(&block) key = nil begin continue = true key = Digest::MD5.hexdigest(Kernel::rand().to_s) Dir.mkdir(@target + '/' + key) rescue continue = false end until continue producer_secret = Digest::MD5.hexdigest(Kernel::rand().to_s) consumer_secret = Digest::MD5.hexdigest(Kernel::rand().to_s) File.open(@target + '/' + key + '/producer-secret','w') { |f| f.write producer_secret } File.open(@target + '/' + key + '/consumer-secret','w') { |f| f.write consumer_secret } XML::Smart::modify(@target + '/' + key + '/subscription.xml',"<subscription xmlns='http://riddl.org/ns/common-patterns/notifications-producer/1.0'/>") do |doc| doc.register_namespace 'n', 'http://riddl.org/ns/common-patterns/notifications-producer/1.0' block.call doc, key end [key, producer_secret, consumer_secret] end |
#each(&block) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 87 def each(&block) keys.each do |key| f = @target + '/' + key + '/subscription.xml' block.call Sub.new(f), key if File.exists? f end end |
#include?(key) ⇒ Boolean
94 95 96 97 |
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 94 def include?(key) f = @target + '/' + key + '/subscription.xml' File.exists?(f) end |
#keys ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 122 def keys if File.directory?(@target) Dir[@target + '/*'].map do |d| File.directory?(d) ? File.basename(d) : nil end.compact else [] end end |