Class: OpenComponents::Component
- Inherits:
-
Object
- Object
- OpenComponents::Component
- Defined in:
- lib/opencomponents/component.rb
Overview
Wrapper object for a component fetched from an OC registry.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#headers ⇒ Object
Public: Gets/sets a Hash of headers to send in the component request.
-
#href ⇒ Object
readonly
Public: Returns the String URL of the requested component.
-
#name ⇒ Object
Public: Gets/sets the String name of the component.
-
#params ⇒ Object
Public: Gets/sets a Hash of params to send in the component request.
-
#registry_version ⇒ Object
readonly
Public: Returns the String version of the component as served by the registry.
-
#render_mode ⇒ Object
readonly
Public: Returns the String render mode of the component as served by the registry.
-
#type ⇒ Object
readonly
Public: Returns the String type of the component as served by the registry.
-
#version ⇒ Object
Public: Gets/sets the desired String version of the component.
Instance Method Summary collapse
-
#flush! ⇒ Object
Public: Resets all component attributes from a registry response to ‘nil`.
-
#initialize(name, opts = {}) ⇒ Component
constructor
Public: Initializes a new Component subclass.
-
#reload! ⇒ Object
Public: Resets all component attributes and reloads them from a registry response.
-
#request_version ⇒ Object
Public: Returns the String value of ‘requestVersion` from a component response, `nil` if not present.
Constructor Details
#initialize(name, opts = {}) ⇒ Component
Public: Initializes a new Component subclass.
name - The String name of the component to request. opts - A Hash of options to use when requesting the component
(default: {}).
:params - A Hash of parameters to send in the component request
(optional, default: {}).
:version - The String version of the component to request
(optional, default: '').
:headers - A Hash of HTTP request headers to include in the
component request (optional, default: {}).
42 43 44 45 46 47 |
# File 'lib/opencomponents/component.rb', line 42 def initialize(name, opts = {}) @name = name @params = opts[:params] || {} @version = opts[:version] || '' @headers = opts[:headers] || {} end |
Instance Attribute Details
#headers ⇒ Object
Public: Gets/sets a Hash of headers to send in the component request.
14 15 16 |
# File 'lib/opencomponents/component.rb', line 14 def headers @headers end |
#href ⇒ Object (readonly)
Public: Returns the String URL of the requested component.
17 18 19 |
# File 'lib/opencomponents/component.rb', line 17 def href @href end |
#name ⇒ Object
Public: Gets/sets the String name of the component.
5 6 7 |
# File 'lib/opencomponents/component.rb', line 5 def name @name end |
#params ⇒ Object
Public: Gets/sets a Hash of params to send in the component request.
11 12 13 |
# File 'lib/opencomponents/component.rb', line 11 def params @params end |
#registry_version ⇒ Object (readonly)
Public: Returns the String version of the component as served by the
registry.
21 22 23 |
# File 'lib/opencomponents/component.rb', line 21 def registry_version @registry_version end |
#render_mode ⇒ Object (readonly)
Public: Returns the String render mode of the component as served by the
registry. Generally either `rendered` or `unrendered`.
29 30 31 |
# File 'lib/opencomponents/component.rb', line 29 def render_mode @render_mode end |
#type ⇒ Object (readonly)
Public: Returns the String type of the component as served by the
registry.
25 26 27 |
# File 'lib/opencomponents/component.rb', line 25 def type @type end |
#version ⇒ Object
Public: Gets/sets the desired String version of the component.
8 9 10 |
# File 'lib/opencomponents/component.rb', line 8 def version @version end |
Instance Method Details
#flush! ⇒ Object
Public: Resets all component attributes from a registry response to ‘nil`.
Examples
component.flush!
# => #<OpenComponents::RenderedComponent: ... >
Returns the reset Component.
63 64 65 66 67 68 69 |
# File 'lib/opencomponents/component.rb', line 63 def flush! flush_variables_whitelist.each do |var| instance_variable_set(var, nil) end self end |
#reload! ⇒ Object
Public: Resets all component attributes and reloads them from a registry
response.
Examples
component.reload!
# => #<OpenComponents::RenderedComponent: ... >
Returns the reloaded Component.
80 81 82 83 |
# File 'lib/opencomponents/component.rb', line 80 def reload! flush! load end |
#request_version ⇒ Object
Public: Returns the String value of ‘requestVersion` from a component
response, `nil` if not present.
51 52 53 |
# File 'lib/opencomponents/component.rb', line 51 def request_version @request_version == '' ? nil : @request_version end |