Class: Masq::Site

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/masq/site.rb

Instance Method Summary collapse

Instance Method Details

#ax_fetch=(props) ⇒ Object

Generates a release policy for each property that has a value. This setter is used in the server controllers complete action to set the attributes recieved from the decision form.



29
30
31
32
33
# File 'app/models/masq/site.rb', line 29

def ax_fetch=(props)
  props.each_pair do |property, details|
    release_policies.build(property: property, type_identifier: details["type"]) if details["value"]
  end
end

#ax_propertiesObject

Returns a hash with all released AX properties. AX properties have a URL as type_identifier.



57
58
59
60
61
62
63
64
65
66
# File 'app/models/masq/site.rb', line 57

def ax_properties
  props = {}
  release_policies.each do |rp|
    if rp.type_identifier.match?("://")
      props["type.#{rp.property}"] = rp.type_identifier
      props["value.#{rp.property}"] = persona.property(rp.type_identifier)
    end
  end
  props
end

#properties=(props) ⇒ Object

Sets the release policies by first deleting the old ones and then appending a new one for every given sreg and ax property. This setter is used to set the attributes received from the update site form, so it gets passed AX and SReg properties. To be backwards compatible (SReg seems to be obsolete now that there is AX), SReg properties get a type_identifier matching their property name so that they can be distinguished from AX properties (see the sreg_properties and ax_properties getters).



19
20
21
22
23
24
# File 'app/models/masq/site.rb', line 19

def properties=(props)
  release_policies.destroy_all
  props.each_pair do |property, details|
    release_policies.build(property: property, type_identifier: details["type"]) if details["value"]
  end
end

#sreg=(props) ⇒ Object

Generates a release policy for each SReg property. This setter is used in the server controllers complete action to set the attributes recieved from the decision form.



38
39
40
41
42
# File 'app/models/masq/site.rb', line 38

def sreg=(props)
  props.each_key do |property|
    release_policies.build(property: property, type_identifier: property)
  end
end

#sreg_propertiesObject

Returns a hash with all released SReg properties. SReg properties have a type_identifier matching their property name



46
47
48
49
50
51
52
53
# File 'app/models/masq/site.rb', line 46

def sreg_properties
  props = {}
  release_policies.each do |rp|
    is_sreg = (rp.property == rp.type_identifier)
    props[rp.property] = persona.property(rp.property) if is_sreg
  end
  props
end