-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencomponents.rb
More file actions
55 lines (46 loc) · 1.5 KB
/
opencomponents.rb
File metadata and controls
55 lines (46 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'json'
require 'net/http'
require 'opencomponents/component'
require 'opencomponents/rendered_component'
require 'opencomponents/renderer'
require 'opencomponents/unrendered_component'
require 'opencomponents/version'
module OpenComponents
# Public: Default OC registry URL (http://localhost:3030).
DEFAULT_REGISTRY = 'http://localhost:3030'
# Public: Default request timeout in seconds (5)
DEFAULT_TIMEOUT = 5
# Internal: Custom exception class to raise in the event a component cannot be
# found in the registry.
ComponentNotFound = Class.new(RuntimeError)
# Internal: Custom exception class to raise for response timeouts.
RegistryTimeout = Class.new(RuntimeError)
# Internal: Stores configuration data.
#
# registry - String for the registry host.
Configuration = Struct.new(:registry, :timeout)
# Internal: Wrapper object for unrendered OC templates.
#
# src - String for the template URL.
# type - String for template engine type.
# key - String for template key.
Template = Struct.new(:src, :type, :key)
# Public: Getter for OC Configuration.
#
# Returns the Configuration if set, a default Configuration if not set.
def self.config
@@_config ||= Configuration.new(DEFAULT_REGISTRY, DEFAULT_TIMEOUT)
end
# Public: Setter for Configuration.
#
# Examples
#
# OpenComponents.configure do |oc|
# oc.registry = 'http://my-awesome-oc-registry.com'
# end
#
# Returns the Configuration.
def self.configure
yield self.config
end
end