Class: SmartProxyFeature

Inherits:
ApplicationRecord show all
Defined in:
app/models/smart_proxy_feature.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

graphql_type, #logger, logger

Methods included from AuditAssociations::AssociationsDefinitions

#audit_associations, #audited, #configure_dirty_associations, #normalize_associations

Class Method Details

.import_features(smart_proxy, features_json) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/smart_proxy_feature.rb', line 13

def self.import_features(smart_proxy, features_json)
  name_map = Feature.name_map
  new_feature_classes = features_json.keys.map { |feature| name_map[feature] }
  smart_proxy.smart_proxy_features.where.not(feature: new_feature_classes).destroy_all
  features_json.each do |name, feature_json|
    feature_class = name_map[name]
    # loop through smart_proxy_features to handle unsaved objects
    smart_proxy_feature = smart_proxy.smart_proxy_features.to_a.find { |spf| spf.feature_id == feature_class.id }
    smart_proxy_feature ||= SmartProxyFeature.new(:feature_id => feature_class.id)
    smart_proxy_feature.import_json(feature_json)
    smart_proxy.smart_proxy_features << smart_proxy_feature
  end
end

Instance Method Details

#detailsObject


9
10
11
# File 'app/models/smart_proxy_feature.rb', line 9

def details
  {settings: settings, capabilities: capabilities}
end

#import_json(feature_json) ⇒ Object


27
28
29
30
# File 'app/models/smart_proxy_feature.rb', line 27

def import_json(feature_json)
  self.capabilities = feature_json[:capabilities]
  self.settings = feature_json[:settings]
end