Class: Stat
- Inherits:
-
Object
- Object
- Stat
- Defined in:
- app/models/stat.rb
Instance Attribute Summary collapse
-
#expose_via_api ⇒ Object
readonly
Returns the value of attribute expose_via_api.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #calculate ⇒ Object
-
#initialize(name, expose_via_api: false, &block) ⇒ Stat
constructor
A new instance of Stat.
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_api ⇒ Object (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 |
#name ⇒ Object (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_stats ⇒ Object
19 20 21 |
# File 'app/models/stat.rb', line 19 def self.all_stats calculate(_all_stats) end |
.api_stats ⇒ Object
23 24 25 |
# File 'app/models/stat.rb', line 23 def self.api_stats calculate(_api_stats) end |
Instance Method Details
#calculate ⇒ Object
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 |