Class: ShareWith::Collection
- Inherits:
-
Object
- Object
- ShareWith::Collection
- Defined in:
- lib/share_with/collection.rb
Overview
Entry point class that handles the service collection.
Instance Attribute Summary collapse
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Instance Method Summary collapse
- #create_or_reset(service) ⇒ Object
- #get_value(service, key) ⇒ Object
-
#initialize(args = {}) ⇒ Collection
constructor
A new instance of Collection.
- #inspect(service, var_path) ⇒ Object
- #param(service, key) ⇒ Object
- #params_list(service) ⇒ Object
- #params_lists ⇒ Object
- #render(service, template) ⇒ Object
- #render_all(template) ⇒ Object
- #reset_all! ⇒ Object
- #set_conditional_param(key, value) ⇒ Object
- #set_param(service, key, value) ⇒ Object
- #set_param_to(services, key, value) ⇒ Object
- #set_param_to_all(key, value) ⇒ Object
- #set_value(service, key, value) ⇒ Object
- #set_value_to(services, key, value) ⇒ Object
- #set_value_to_all(key, value) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Collection
Returns a new instance of Collection.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/share_with/collection.rb', line 10 def initialize(args = {}) @paths = args[:paths] || [] @extend_with = args[:extend_with] || [] @services = {} return unless args[:services] args[:services].each do |s| @services[s.to_sym] = Service.new(s, { paths: @paths, extend_with: @extend_with }) end end |
Instance Attribute Details
#services ⇒ Object (readonly)
Returns the value of attribute services.
8 9 10 |
# File 'lib/share_with/collection.rb', line 8 def services @services end |
Instance Method Details
#create_or_reset(service) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/share_with/collection.rb', line 86 def create_or_reset(service) if @services.include? service.to_sym @services[service.to_sym].reset! else @services[service.to_sym] = Service.new(service, { paths: @paths, extend_with: @extend_with }) end end |
#get_value(service, key) ⇒ Object
66 67 68 |
# File 'lib/share_with/collection.rb', line 66 def get_value(service, key) @services[service.to_sym].get_value(key) end |
#inspect(service, var_path) ⇒ Object
21 22 23 |
# File 'lib/share_with/collection.rb', line 21 def inspect(service, var_path) @services[service.to_sym].inspect(var_path) end |
#param(service, key) ⇒ Object
25 26 27 |
# File 'lib/share_with/collection.rb', line 25 def param(service, key) @services[service.to_sym].get_param(key) if @services.key?(service.to_sym) end |
#params_list(service) ⇒ Object
29 30 31 |
# File 'lib/share_with/collection.rb', line 29 def params_list(service) @services[service.to_sym].params_list if @services.key?(service.to_sym) end |
#params_lists ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/share_with/collection.rb', line 33 def params_lists res = [] services.each do |s| res.push(*params_list(s)) end res.uniq end |
#render(service, template) ⇒ Object
100 101 102 |
# File 'lib/share_with/collection.rb', line 100 def render(service, template) @services[service.to_sym].render(template) end |
#render_all(template) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/share_with/collection.rb', line 104 def render_all(template) res = {} @services.each do |k, _v| res[k] = render(k, template) end res end |
#reset_all! ⇒ Object
94 95 96 97 98 |
# File 'lib/share_with/collection.rb', line 94 def reset_all! @services.each do |_k, s| s.reset! end end |
#set_conditional_param(key, value) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/share_with/collection.rb', line 57 def set_conditional_param(key, value) if key.include? ":" services, param = key.split(":") set_param_to(services.split(","), param, value) else set_param_to_all(key, value) end end |
#set_param(service, key, value) ⇒ Object
41 42 43 |
# File 'lib/share_with/collection.rb', line 41 def set_param(service, key, value) @services[service.to_sym].set_param(key, value) if @services.key?(service.to_sym) end |
#set_param_to(services, key, value) ⇒ Object
45 46 47 48 49 |
# File 'lib/share_with/collection.rb', line 45 def set_param_to(services, key, value) services.each do |s| set_param s, key, value if @services.key? s.to_sym end end |
#set_param_to_all(key, value) ⇒ Object
51 52 53 54 55 |
# File 'lib/share_with/collection.rb', line 51 def set_param_to_all(key, value) @services.each_key do |s| set_param(s, key, value) end end |
#set_value(service, key, value) ⇒ Object
70 71 72 |
# File 'lib/share_with/collection.rb', line 70 def set_value(service, key, value) @services[service.to_sym].set_value(key, value) end |
#set_value_to(services, key, value) ⇒ Object
74 75 76 77 78 |
# File 'lib/share_with/collection.rb', line 74 def set_value_to(services, key, value) services.each do |s| set_value s, key, value if @services.key? s.to_sym end end |
#set_value_to_all(key, value) ⇒ Object
80 81 82 83 84 |
# File 'lib/share_with/collection.rb', line 80 def set_value_to_all(key, value) @services.each_key do |s| set_value(s, key, value) end end |