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
requestVersionfrom a component response,nilif 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: {}).
44 45 46 47 48 49 |
# File 'lib/opencomponents/component.rb', line 44 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.
16 17 18 |
# File 'lib/opencomponents/component.rb', line 16 def headers @headers end |
#href ⇒ Object (readonly)
Public: Returns the String URL of the requested component.
19 20 21 |
# File 'lib/opencomponents/component.rb', line 19 def href @href end |
#name ⇒ Object
Public: Gets/sets the String name of the component.
7 8 9 |
# File 'lib/opencomponents/component.rb', line 7 def name @name end |
#params ⇒ Object
Public: Gets/sets a Hash of params to send in the component request.
13 14 15 |
# File 'lib/opencomponents/component.rb', line 13 def params @params end |
#registry_version ⇒ Object (readonly)
Public: Returns the String version of the component as served by the
registry.
23 24 25 |
# File 'lib/opencomponents/component.rb', line 23 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 `pre-rendered`.
31 32 33 |
# File 'lib/opencomponents/component.rb', line 31 def render_mode @render_mode end |
#type ⇒ Object (readonly)
Public: Returns the String type of the component as served by the
registry.
27 28 29 |
# File 'lib/opencomponents/component.rb', line 27 def type @type end |
#version ⇒ Object
Public: Gets/sets the desired String version of the component.
10 11 12 |
# File 'lib/opencomponents/component.rb', line 10 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.
65 66 67 68 69 70 71 |
# File 'lib/opencomponents/component.rb', line 65 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.
82 83 84 85 |
# File 'lib/opencomponents/component.rb', line 82 def reload! flush! load end |
#request_version ⇒ Object
Public: Returns the String value of requestVersion from a component
response, `nil` if not present.
53 54 55 |
# File 'lib/opencomponents/component.rb', line 53 def request_version @request_version == '' ? nil : @request_version end |