Class: Heathrow::Sources::Base
- Inherits:
-
Object
- Object
- Heathrow::Sources::Base
show all
- Defined in:
- lib/heathrow/sources/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, config, db) ⇒ Base
Returns a new instance of Base.
6
7
8
9
10
11
|
# File 'lib/heathrow/sources/base.rb', line 6
def initialize(name, config, db)
@name = name
@config = config
@db = db
@type = self.class.name.split('::').last.downcase
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4
5
6
|
# File 'lib/heathrow/sources/base.rb', line 4
def config
@config
end
|
#db ⇒ Object
Returns the value of attribute db.
4
5
6
|
# File 'lib/heathrow/sources/base.rb', line 4
def db
@db
end
|
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'lib/heathrow/sources/base.rb', line 4
def name
@name
end
|
#type ⇒ Object
Returns the value of attribute type.
4
5
6
|
# File 'lib/heathrow/sources/base.rb', line 4
def type
@type
end
|
Instance Method Details
#enabled? ⇒ Boolean
21
22
23
|
# File 'lib/heathrow/sources/base.rb', line 21
def enabled?
@config['enabled'] != false
end
|
#fetch ⇒ Object
13
14
15
|
# File 'lib/heathrow/sources/base.rb', line 13
def fetch
raise NotImplementedError, "#{self.class} must implement #fetch"
end
|
#last_fetch ⇒ Object
25
26
27
|
# File 'lib/heathrow/sources/base.rb', line 25
def last_fetch
@config['last_fetch']
end
|
#poll_interval ⇒ Object
17
18
19
|
# File 'lib/heathrow/sources/base.rb', line 17
def poll_interval
@config['poll_interval'] || 300
end
|
#save_config ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/heathrow/sources/base.rb', line 34
def save_config
source = @db.get_source_by_name(@name)
if source
sid = source['id'] || source[:id]
@db.update_source(sid, config: @config.to_json) if sid
end
end
|
#update_last_fetch(time = Time.now) ⇒ Object
29
30
31
32
|
# File 'lib/heathrow/sources/base.rb', line 29
def update_last_fetch(time = Time.now)
@config['last_fetch'] = time.to_i
save_config
end
|