Class: SharingTags::Context
- Inherits:
-
Object
- Object
- SharingTags::Context
show all
- Defined in:
- lib/sharing_tags/context.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, configuraton) ⇒ Context
Returns a new instance of Context.
6
7
8
9
10
11
12
13
14
|
# File 'lib/sharing_tags/context.rb', line 6
def initialize(name, configuraton)
@name = name
@networks = {}
@configuraton = configuraton
Network.lists.each do |network_name|
send(network_name)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/sharing_tags/context.rb', line 98
def method_missing(method_name, *arguments, &block)
unless default_network.class.available_attributes.include?(method_name.to_sym)
fail Network::Error, "Error didn't find #{method_name} attribute in network"
end
default_network.send(method_name, *arguments, &block)
end
|
Instance Attribute Details
#configuraton ⇒ Object
Returns the value of attribute configuraton.
4
5
6
|
# File 'lib/sharing_tags/context.rb', line 4
def configuraton
@configuraton
end
|
#name ⇒ Object
Returns the value of attribute name.
3
4
5
|
# File 'lib/sharing_tags/context.rb', line 3
def name
@name
end
|
Instance Method Details
#[](network) ⇒ Object
16
17
18
|
# File 'lib/sharing_tags/context.rb', line 16
def [](network)
@networks[network]
end
|
#default_network ⇒ Object
66
67
68
|
# File 'lib/sharing_tags/context.rb', line 66
def default_network
@default_network ||= Network.new(:default, self)
end
|
#facebook(&block) ⇒ Object
26
27
28
29
30
|
# File 'lib/sharing_tags/context.rb', line 26
def facebook(&block)
(@networks[:facebook] ||= Network::Facebook.new(:facebook, self)).tap do |facebook|
facebook.instance_exec(&block) if block_given?
end
end
|
#google(&block) ⇒ Object
32
33
34
35
36
|
# File 'lib/sharing_tags/context.rb', line 32
def google(&block)
(@networks[:google] ||= Network.new(:google, self)).tap do |google|
google.instance_exec(&block) if block_given?
end
end
|
#line(&block) ⇒ Object
44
45
46
47
48
|
# File 'lib/sharing_tags/context.rb', line 44
def line(&block)
(@networks[:line] ||= Network.new(:line, self)).tap do |line|
line.instance_exec(&block) if block_given?
end
end
|
#linkedin(&block) ⇒ Object
56
57
58
59
60
|
# File 'lib/sharing_tags/context.rb', line 56
def linkedin(&block)
(@networks[:linkedin] ||= Network.new(:linkedin, self)).tap do |vkontakte|
vkontakte.instance_exec(&block) if block_given?
end
end
|
#odnoklassniki(&block) ⇒ Object
50
51
52
53
54
|
# File 'lib/sharing_tags/context.rb', line 50
def odnoklassniki(&block)
(@networks[:odnoklassniki] ||= Network.new(:odnoklassniki, self)).tap do |odnoklassniki|
odnoklassniki.instance_exec(&block) if block_given?
end
end
|
#params(context_args = nil, default_config_params = Config.new) ⇒ Object
62
63
64
|
# File 'lib/sharing_tags/context.rb', line 62
def params(context_args = nil, default_config_params = Config.new)
@context_params = fetch_params(context_args, default_config_params)
end
|
20
21
22
23
24
|
# File 'lib/sharing_tags/context.rb', line 20
def (&block)
(@networks[:twitter] ||= Network.new(:twitter, self)).tap do ||
.instance_exec(&block) if block_given?
end
end
|
#vkontakte(&block) ⇒ Object
38
39
40
41
42
|
# File 'lib/sharing_tags/context.rb', line 38
def vkontakte(&block)
(@networks[:vkontakte] ||= Network.new(:vkontakte, self)).tap do |vkontakte|
vkontakte.instance_exec(&block) if block_given?
end
end
|