Class: Stat

Inherits:
Object
  • Object
show all
Defined in:
app/models/stat.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, expose_via_api: false, &block) ⇒ Stat

Returns a new instance of Stat.



4
5
6
7
8
# File 'app/models/stat.rb', line 4

def initialize(name, expose_via_api: false, &block)
  @name = name
  @expose_via_api = expose_via_api
  @block = block
end

Instance Attribute Details

#expose_via_apiObject (readonly)

Returns the value of attribute expose_via_api.



10
11
12
# File 'app/models/stat.rb', line 10

def expose_via_api
  @expose_via_api
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'app/models/stat.rb', line 10

def name
  @name
end

Class Method Details

.all_statsObject



19
20
21
# File 'app/models/stat.rb', line 19

def self.all_stats
  calculate(_all_stats)
end

.api_statsObject



23
24
25
# File 'app/models/stat.rb', line 23

def self.api_stats
  calculate(_api_stats)
end

Instance Method Details

#calculateObject



12
13
14
15
16
17
# File 'app/models/stat.rb', line 12

def calculate
  @block.call.transform_keys { |key| build_key(key) }
rescue StandardError => err
  Discourse.warn_exception(err, message: "Unexpected error when collecting #{@name} About stats.")
  {}
end