Module: Motor::Configs::BuildConfigsHash
- Defined in:
- lib/motor/configs/build_configs_hash.rb
Class Method Summary collapse
- .build_alerts_hash(cache_key = nil) ⇒ Object
- .build_api_configs_hash(cache_key = nil) ⇒ Object
- .build_configs_hash(cache_key = nil) ⇒ Object
- .build_dashboards_hash(cache_key = nil) ⇒ Object
- .build_forms_hash(cache_key = nil) ⇒ Object
-
.build_queries_hash(cache_key = nil) ⇒ Object
rubocop:enable Metrics/AbcSize.
- .build_resources_hash(cache_key = nil) ⇒ Object
-
.call ⇒ Object
rubocop:disable Metrics/AbcSize.
- .normalize_hash(value) ⇒ Object
Class Method Details
.build_alerts_hash(cache_key = nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/motor/configs/build_configs_hash.rb', line 40 def build_alerts_hash(cache_key = nil) Motor::Configs::LoadFromCache.load_alerts(cache_key: cache_key).sort_by(&:id).map do |alert| alert.slice(%i[id name query_id to_emails is_enabled description preferences]) .merge(tags: alert..map(&:name), updated_at: alert.updated_at.to_time) end end |
.build_api_configs_hash(cache_key = nil) ⇒ Object
54 55 56 57 58 |
# File 'lib/motor/configs/build_configs_hash.rb', line 54 def build_api_configs_hash(cache_key = nil) Motor::Configs::LoadFromCache.load_api_configs(cache_key: cache_key).sort_by(&:id).map do |config| config.slice(%i[id name url preferences description]).merge(updated_at: config.updated_at.to_time) end end |
.build_configs_hash(cache_key = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/motor/configs/build_configs_hash.rb', line 60 def build_configs_hash(cache_key = nil) Motor::Configs::LoadFromCache.load_configs(cache_key: cache_key).sort_by(&:key).map do |config| { key: config.key, value: config.value, updated_at: config.updated_at.to_time } end end |
.build_dashboards_hash(cache_key = nil) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/motor/configs/build_configs_hash.rb', line 33 def build_dashboards_hash(cache_key = nil) Motor::Configs::LoadFromCache.load_dashboards(cache_key: cache_key).sort_by(&:id).map do |dashboard| dashboard.slice(%i[id title description preferences]) .merge(tags: dashboard..map(&:name), updated_at: dashboard.updated_at.to_time) end end |
.build_forms_hash(cache_key = nil) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/motor/configs/build_configs_hash.rb', line 47 def build_forms_hash(cache_key = nil) Motor::Configs::LoadFromCache.load_forms(cache_key: cache_key).sort_by(&:id).map do |form| form.slice(%i[id name http_method api_path description preferences api_config_name]) .merge(tags: form..map(&:name), updated_at: form.updated_at.to_time) end end |
.build_queries_hash(cache_key = nil) ⇒ Object
rubocop:enable Metrics/AbcSize
26 27 28 29 30 31 |
# File 'lib/motor/configs/build_configs_hash.rb', line 26 def build_queries_hash(cache_key = nil) Motor::Configs::LoadFromCache.load_queries(cache_key: cache_key).sort_by(&:id).map do |query| query.slice(%i[id name sql_body description preferences]) .merge(tags: query..map(&:name), updated_at: query.updated_at.to_time) end end |
.build_resources_hash(cache_key = nil) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/motor/configs/build_configs_hash.rb', line 70 def build_resources_hash(cache_key = nil) Motor::Configs::LoadFromCache.load_resources(cache_key: cache_key).sort_by(&:name).map do |resource| { name: resource.name, preferences: resource.preferences, updated_at: resource.updated_at.to_time } end end |
.call ⇒ Object
rubocop:disable Metrics/AbcSize
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/motor/configs/build_configs_hash.rb', line 9 def call cache_keys = LoadFromCache.load_cache_keys normalize_hash( engine_version: Motor::VERSION, file_version: cache_keys.values.compact.max.to_time, resources: build_resources_hash(cache_keys[:resources]), configs: build_configs_hash(cache_keys[:configs]), queries: build_queries_hash(cache_keys[:queries]), dashboards: build_dashboards_hash(cache_keys[:dashboards]), forms: build_forms_hash(cache_keys[:forms]), alerts: build_alerts_hash(cache_keys[:alerts]), api_configs: build_api_configs_hash(cache_keys[:api_configs]) ) end |
.normalize_hash(value) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/motor/configs/build_configs_hash.rb', line 80 def normalize_hash(value) case value when Hash, HashWithIndifferentAccess value.to_h.stringify_keys.transform_values { |v| normalize_hash(v) } when Array value.map { |e| normalize_hash(e) } else value end end |