Class: Noah::Watcher

Inherits:
Model
  • Object
show all
Includes:
WatcherValidations
Defined in:
lib/noah/models/watchers.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WatcherValidations

#assert_not_subset, #assert_not_superset, #assert_valid_watch

Methods inherited from Model

inherited

Class Method Details

.find_by_name(name) ⇒ Object



31
32
33
34
# File 'lib/noah/models/watchers.rb', line 31

def find_by_name(name)
  pattern, endpoint = Base64.decode64(name).split('|')
  find(:pattern => pattern, :endpoint => endpoint).first
end

.watch_listObject



36
37
38
39
40
41
# File 'lib/noah/models/watchers.rb', line 36

def watch_list
  arr = []
  watches = self.all.sort_by(:pattern)
  watches.each {|w| arr << w.to_hash}
  arr
end

Instance Method Details

#nameObject



21
22
23
# File 'lib/noah/models/watchers.rb', line 21

def name
  @name = Base64.encode64("#{pattern}|#{endpoint}").gsub("\n","")
end

#to_hashObject



25
26
27
28
# File 'lib/noah/models/watchers.rb', line 25

def to_hash
  h = {:pattern => pattern, :name => name, :endpoint => endpoint, :created_at => created_at, :updated_at => updated_at}
  super.merge(h)
end

#validateObject



12
13
14
15
16
17
18
19
# File 'lib/noah/models/watchers.rb', line 12

def validate
  super
  assert_present :endpoint
  assert_present :pattern
  assert_unique [:endpoint, :pattern]
  assert_not_superset
  assert_not_subset
end