Class: Para::ComponentsConfiguration::Component
- Inherits:
-
Object
- Object
- Para::ComponentsConfiguration::Component
- Defined in:
- lib/para/components_configuration.rb
Instance Attribute Summary collapse
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#model ⇒ Object
Returns the value of attribute model.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(identifier, type_identifier, options = {}) ⇒ Component
constructor
A new instance of Component.
-
#options_with_defaults ⇒ Object
Ensures unset :configuration store options are set to nil to allow removing a configuration option from the components.rb file.
- #refresh(attributes = {}) ⇒ Object
Constructor Details
#initialize(identifier, type_identifier, options = {}) ⇒ Component
Returns a new instance of Component.
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/para/components_configuration.rb', line 139 def initialize(identifier, type_identifier, = {}) self.identifier = identifier.to_s self.type = Para::Component.registered_components[type_identifier] self. = unless type raise UndefinedComponentTypeError.new( "Undefined Para component : #{ type_identifier }. " + "Please ensure that your app or gems define this component type." ) end end |
Instance Attribute Details
#identifier ⇒ Object
Returns the value of attribute identifier.
137 138 139 |
# File 'lib/para/components_configuration.rb', line 137 def identifier @identifier end |
#model ⇒ Object
Returns the value of attribute model.
137 138 139 |
# File 'lib/para/components_configuration.rb', line 137 def model @model end |
#options ⇒ Object
Returns the value of attribute options.
137 138 139 |
# File 'lib/para/components_configuration.rb', line 137 def @options end |
#type ⇒ Object
Returns the value of attribute type.
137 138 139 |
# File 'lib/para/components_configuration.rb', line 137 def type @type end |
Instance Method Details
#options_with_defaults ⇒ Object
Ensures unset :configuration store options are set to nil to allow removing a configuration option from the components.rb file
161 162 163 164 165 166 167 168 169 |
# File 'lib/para/components_configuration.rb', line 161 def configurable_keys = type.local_stored_attributes.try(:[], :configuration) || [] configurable_keys += .keys configurable_keys.uniq! configurable_keys.each_with_object({}) do |key, hash| hash[key] = [key] end end |
#refresh(attributes = {}) ⇒ Object
152 153 154 155 156 |
# File 'lib/para/components_configuration.rb', line 152 def refresh(attributes = {}) self.model = type.where(identifier: identifier).first_or_initialize model.assign_attributes(attributes.merge()) model.save! end |