Class: Springcm::AttributeGroup
- Defined in:
- lib/springcm-sdk/attribute_group.rb
Overview
A configured attribute group in SpringCM.
Instance Method Summary collapse
- #attributes ⇒ Object
-
#field(name) ⇒ Object
Retrieve an attribute field by name.
-
#set(name) ⇒ Object
Retrieve an attribute set by name.
- #set_for_field(name) ⇒ Object
- #sets ⇒ Object
- #template ⇒ Object
Methods inherited from Resource
#delete, #get, #patch, #put, #reload, #reload!, #resource_name, #resource_params, resource_params, #resource_uri, #uid
Methods inherited from Object
#initialize, #method_missing, #raw
Constructor Details
This class inherits a constructor from Springcm::Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Springcm::Object
Instance Method Details
#attributes ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/springcm-sdk/attribute_group.rb', line 40 def attributes attributes_config.map { |attr| if attr["Attributes"].is_a?(Array) attr["Attributes"] else [attr] end }.flatten end |
#field(name) ⇒ Object
Retrieve an attribute field by name.
19 20 21 22 23 24 25 26 |
# File 'lib/springcm-sdk/attribute_group.rb', line 19 def field(name) res = attributes.select { |attr| attr["Name"] == name } return nil if !res.any? # TODO: Assert only one result Attribute.new(res.first, @client) end |
#set(name) ⇒ Object
Retrieve an attribute set by name.
8 9 10 11 12 13 14 15 16 |
# File 'lib/springcm-sdk/attribute_group.rb', line 8 def set(name) res = attributes_config.select { |attr| attr["Attributes"].is_a?(Array) && attr["Name"] == name } return nil if !res.any? res.first["Attributes"].map { |attr| Attribute.new(attr, @client) } end |
#set_for_field(name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/springcm-sdk/attribute_group.rb', line 28 def set_for_field(name) if sets.map { |set| set["Name"] }.include?(name) return nil end sets.each { |set| if set["Attributes"].map { |attr| attr["Name"] }.include?(name) return set end } nil end |
#sets ⇒ Object
50 51 52 53 54 |
# File 'lib/springcm-sdk/attribute_group.rb', line 50 def sets attributes_config.select { |attr| attr["Attributes"].is_a?(Array) } end |
#template ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/springcm-sdk/attribute_group.rb', line 56 def template group = {} attributes_config.each { |attribute| type = attribute["Type"] if type == "DynamicDropDown" type = "MagicDropdown" # Not sure why they do this for applied groups, but oh well end repeating = attribute["RepeatingAttribute"] attr = { "AttributeType" => type, "RepeatingAttribute" => repeating } if attribute.key?("Attributes") # If it's a set attr["AttributeType"] = "Set" set = attr if repeating set = {} attr["Items"] = [set] end attribute["Attributes"].each { |field| set[field["Name"]] = { "AttributeType" => field["Type"], "RepeatingAttribute" => false } } elsif repeating # Must have empty array for repeating plain fields attr["Value"] = [] end group[attribute["Name"]] = attr } group end |