Class: SkadateGems::Dev::Remote::Configs

Inherits:
Object
  • Object
show all
Defined in:
lib/skadategems/dev/remote/configs.rb

Overview

Represents remote application configurations accessor.

Defined Under Namespace

Classes: Config

Instance Method Summary collapse

Constructor Details

#initialize(remote) ⇒ Configs

Returns a new instance of Configs.

Parameters:

  • remote (Remote)

    skadate remote app



12
13
14
# File 'lib/skadategems/dev/remote/configs.rb', line 12

def initialize(remote)
  @remote = remote
end

Instance Method Details

#[](section_path_or_id) ⇒ Object

Configuration value accessor method.

Parameters:

  • section_path_or_id (Fixnum|String)

    config section path or ‘config_id`



18
19
20
21
22
23
24
25
26
27
# File 'lib/skadategems/dev/remote/configs.rb', line 18

def [](section_path_or_id)
  case section_path_or_id.class.to_s
    when 'String'
      raise 'Getting remote configs by path is currently not implemented'
    when 'Fixnum'
      get_by_id(section_path_or_id)
    else
      raise ArgumentError, "unexpected `section_path_or_id` type #{section_path_or_id.class}"
  end
end

#get_by_id(config_id) ⇒ Object

Parameters:

  • config_id (Fixnum)

    configuration id



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/skadategems/dev/remote/configs.rb', line 30

def get_by_id(config_id)
  response = @remote.exec include: 'mysql_connect' do |script|
    script << <<-PHPSCRIPT
$result = $mysql->query("SELECT `name`, `value` FROM `".TBL_CONFIG."` WHERE `config_id`=#{config_id}");
$config = $result->fetch_object();
echo '{ ';
echo '"name": "'.$config->name.'", ';
echo '"value": '.$config->value;
echo ' }';
    PHPSCRIPT
  end

  result = JSON.parse(response.body)

  Config.new(@remote, config_id, result['name'], result['value'])
end