Class: SkadateGems::Dev::Remote::Configs
- Inherits:
-
Object
- Object
- SkadateGems::Dev::Remote::Configs
- Defined in:
- lib/skadategems/dev/remote/configs.rb
Overview
Represents remote application configurations accessor.
Defined Under Namespace
Classes: Config
Instance Method Summary collapse
-
#[](section_path_or_id) ⇒ Object
Configuration value accessor method.
- #get_by_id(config_id) ⇒ Object
-
#initialize(remote) ⇒ Configs
constructor
A new instance of Configs.
Constructor Details
#initialize(remote) ⇒ Configs
Returns a new instance of Configs.
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.
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
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 |