Class: ShareWith::Service
- Inherits:
-
Object
- Object
- ShareWith::Service
- Includes:
- LinkFactory, Placeholders
- Defined in:
- lib/share_with/service.rb
Overview
The single service classification.
Instance Method Summary collapse
- #add_layer(layer) ⇒ Object
- #get_param(key) ⇒ Object
- #get_value(key) ⇒ Object
-
#initialize(service_name, args = {}) ⇒ Service
constructor
A new instance of Service.
- #param?(key) ⇒ Boolean
- #params_list ⇒ Object
- #reset! ⇒ Object
- #set_conditional_param(key, value) ⇒ Object
- #set_param(key, value) ⇒ Object
- #set_value(key, value) ⇒ Object
Methods included from LinkFactory
Methods included from Placeholders
Constructor Details
#initialize(service_name, args = {}) ⇒ Service
Returns a new instance of Service.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/share_with/service.rb', line 13 def initialize(service_name, args = {}) @name = service_name @paths = [].concat args[:paths].to_a @extend_with = args[:extend_with] || [] @paths << File.join(File.dirname(__FILE__), "services") @data = load(@name) @data = inherit_from(info[:inherit_from]) if info.key?(:inherit_from) @extend_with = (info[:extend_with] || []).concat(@extend_with) if info.key?(:extend_with) # if info.key?(:extend_with) if @extend_with # extend_with_layers(info[:extend_with]) extend_with_layers(@extend_with) else # Create the params when no more extensions are requested. create_params end end |
Instance Method Details
#add_layer(layer) ⇒ Object
77 78 79 80 |
# File 'lib/share_with/service.rb', line 77 def add_layer(layer) @extend_with << layer extend_with_layers(layer) end |
#get_param(key) ⇒ Object
42 43 44 |
# File 'lib/share_with/service.rb', line 42 def get_param(key) return params[key.to_sym].value if param?(key) end |
#get_value(key) ⇒ Object
59 60 61 62 63 |
# File 'lib/share_with/service.rb', line 59 def get_value(key) raise InvalidParam, "params.#{key}" unless param?(key.to_sym) params[key.to_sym].value end |
#param?(key) ⇒ Boolean
34 35 36 |
# File 'lib/share_with/service.rb', line 34 def param?(key) params.key?(key.to_sym) end |
#params_list ⇒ Object
38 39 40 |
# File 'lib/share_with/service.rb', line 38 def params_list params.keys end |
#reset! ⇒ Object
71 72 73 74 75 |
# File 'lib/share_with/service.rb', line 71 def reset! params.each { |_k, v| v.reset! } includes.each { |_k, v| v.delete :cache } # extend_with_layers(@extend_with) end |
#set_conditional_param(key, value) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/share_with/service.rb', line 50 def set_conditional_param(key, value) if key.include? ":" services, param = key.split(":") set_param(param, value) if services.split(",").include?(@name) else set_param(key, value) end end |
#set_param(key, value) ⇒ Object
46 47 48 |
# File 'lib/share_with/service.rb', line 46 def set_param(key, value) params[key.to_sym].value = value if param?(key) end |
#set_value(key, value) ⇒ Object
65 66 67 68 69 |
# File 'lib/share_with/service.rb', line 65 def set_value(key, value) raise InvalidParam, "params.#{key}" unless param?(key.to_sym) params[key.to_sym].value = value end |