Class: DistributedCache::Config

Inherits:
Struct
  • Object
show all
Defined in:
lib/distributed_cache/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



11
12
13
14
15
16
# File 'lib/distributed_cache/config.rb', line 11

def initialize
  self.file_server_port = 80
  self.remote_bundle_dir = 'cache/bundles'
  self.cache_dir = "#{Rails.root}/cache" if defined?(Rails)
  self.bundle_dir = "#{Rails.root}/bundles" if defined?(Rails)
end

Instance Attribute Details

#bundle_dirObject

Returns the value of attribute bundle_dir

Returns:

  • (Object)

    the current value of bundle_dir



2
3
4
# File 'lib/distributed_cache/config.rb', line 2

def bundle_dir
  @bundle_dir
end

#cache_dirObject

Returns the value of attribute cache_dir

Returns:

  • (Object)

    the current value of cache_dir



2
3
4
# File 'lib/distributed_cache/config.rb', line 2

def cache_dir
  @cache_dir
end

#file_server_bundle_dirObject

Returns the value of attribute file_server_bundle_dir

Returns:

  • (Object)

    the current value of file_server_bundle_dir



2
3
4
# File 'lib/distributed_cache/config.rb', line 2

def file_server_bundle_dir
  @file_server_bundle_dir
end

#file_server_portObject

Returns the value of attribute file_server_port

Returns:

  • (Object)

    the current value of file_server_port



2
3
4
# File 'lib/distributed_cache/config.rb', line 2

def file_server_port
  @file_server_port
end

#file_server_userObject

Returns the value of attribute file_server_user

Returns:

  • (Object)

    the current value of file_server_user



2
3
4
# File 'lib/distributed_cache/config.rb', line 2

def file_server_user
  @file_server_user
end

#file_serversObject

Returns the value of attribute file_servers

Returns:

  • (Object)

    the current value of file_servers



2
3
4
# File 'lib/distributed_cache/config.rb', line 2

def file_servers
  @file_servers
end

#remote_bundle_dirObject

Returns the value of attribute remote_bundle_dir

Returns:

  • (Object)

    the current value of remote_bundle_dir



2
3
4
# File 'lib/distributed_cache/config.rb', line 2

def remote_bundle_dir
  @remote_bundle_dir
end

Instance Method Details

#file_server_with_portObject



25
26
27
28
29
30
31
# File 'lib/distributed_cache/config.rb', line 25

def file_server_with_port
  if self.file_server_port == 80
    next_file_server
  else
    "#{next_file_server}:#{self.file_server_port}"
  end
end

#next_file_serverObject



18
19
20
21
22
23
# File 'lib/distributed_cache/config.rb', line 18

def next_file_server
  @first_file_server_idx ||= rand(self.file_servers.size)
  self.file_servers[@first_file_server_idx].tap do
    @first_file_server_idx = (@first_file_server_idx + 1) % self.file_servers.size
  end
end