Class: Eco::API::Session::Batch::RequestStats
- Defined in:
- lib/eco/api/session/batch/request_stats.rb
Constant Summary collapse
- CORE_ATTRS =
Eco::API::Common::People::PersonParser::CORE_ATTRS
- ACCOUNT_ATTRS =
(Eco::API::Common::People::PersonParser::ACCOUNT_ATTRS + ["permissions_custom"]).uniq
- DETAILS_ATTRS =
["fields"]
- BLANKED_PREFIX =
"blanked_"
- DETAILS_FIELDS =
"details_fields"
Instance Attribute Summary collapse
-
#count ⇒ Integer
readonly
the total number of requests.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .account_attrs(stats: false, all: false) ⇒ Object
- .blank_attrs(attrs) ⇒ Object
- .blanked_prefix(attr = nil) ⇒ Object
- .blanked_prefix=(value) ⇒ Object
- .core_attrs(stats: false, all: false) ⇒ Object
- .details_attrs(stats: false, all: false) ⇒ Object
- .valid_type?(type) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(type:, requests: []) ⇒ RequestStats
constructor
A new instance of RequestStats.
- #message(percent: false) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(type:, requests: []) ⇒ RequestStats
Returns a new instance of RequestStats.
66 67 68 69 70 71 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 66 def initialize(type:, requests: []) raise "type should be one of #{Eco::API::Session::Batch::Job.types}. Given: #{type}" unless self.class.valid_type?(type.to_sym) @type = type.to_sym @count = requests && requests.length @stats = build(requests) end |
Instance Attribute Details
#count ⇒ Integer (readonly)
the total number of requests
7 8 9 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 7 def count @count end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
64 65 66 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 64 def type @type end |
Class Method Details
.account_attrs(stats: false, all: false) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 29 def account_attrs(stats: false, all: false) ACCOUNT_ATTRS.dup.tap do |attrs| if stats || all attrs.unshift("account_remove") attrs.unshift("account") if all attrs.concat(blank_attrs(ACCOUNT_ATTRS)) end end end |
.blank_attrs(attrs) ⇒ Object
58 59 60 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 58 def blank_attrs(attrs) attrs.map {|attr| "#{blanked_prefix}#{attr}"} end |
.blanked_prefix(attr = nil) ⇒ Object
48 49 50 51 52 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 48 def blanked_prefix(attr = nil) @blanked_prefix ||= BLANKED_PREFIX return @blanked_prefix unless attr "#{blanked_prefix}#{attr}" end |
.blanked_prefix=(value) ⇒ Object
54 55 56 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 54 def blanked_prefix=(value) @blanked_prefix = value || blanked_prefix end |
.core_attrs(stats: false, all: false) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 20 def core_attrs(stats: false, all: false) CORE_ATTRS.dup.tap do |attrs| if stats || all attrs.unshift("core") attrs.concat(blank_attrs(CORE_ATTRS)) end end end |
.details_attrs(stats: false, all: false) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 39 def details_attrs(stats: false, all: false) DETAILS_ATTRS.dup.tap do |attrs| if stats || all attrs.unshift("details_remove") attrs.unshift("details") if all end end end |
Instance Method Details
#message(percent: false) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 77 def (percent: false) lines = [] lines << pairs_to_line(core_pairs(percent: percent)) lines << pairs_to_line(account_pairs(percent: percent)) lines << pairs_to_line(details_pairs(percent: percent)) lines.join("\n") end |
#to_h ⇒ Object
73 74 75 |
# File 'lib/eco/api/session/batch/request_stats.rb', line 73 def to_h @stats end |