Class: Riddl::Utils::Notifications::Producer::Backend

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/utils/notifications_producer.rb

Overview

}}}

Defined Under Namespace

Classes: Sub, Subs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topics, target, init = nil) ⇒ Backend

}}}



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 133

def initialize(topics,target,init=nil)
  @target = target.gsub(/^\/+/,'/')

  unless File.exists?(@target)
    if init
      FileUtils::cp_r init, @target
    else
      FileUtils::mkdir_p(@target)
    end
  end

  raise "topics file not found" unless File.exists?(topics)
  @topics = XML::Smart.open_unprotected(topics.gsub(/^\/+/,'/'))
  @topics.register_namespace 'n', 'http://riddl.org/ns/common-patterns/notifications-producer/1.0'

  subscriptions.each do |sub,key|
    sub.read do |doc|
      if doc.find('/*[@url]').empty?
        sub.delete
      end
    end
  end
end

Instance Attribute Details

#topicsObject (readonly)

{{{



56
57
58
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 56

def topics
  @topics
end

Instance Method Details

#subscriptionsObject



157
158
159
# File 'lib/ruby/riddl/utils/notifications_producer.rb', line 157

def subscriptions
  Subs.new(@target)
end