Class: SleipnirAPI::Profile::Ini
- Inherits:
-
ProfileElement
- Object
- ProfileElement
- SleipnirAPI::Profile::Ini
- Defined in:
- lib/sleipnir_api/profile/ini.rb
Overview
ini ファイルに対応するオブジェクトです。このオブジェクトは SleipnirAPI::Sleipnir#profile でまたは SleipnirAPI::Profile#ini で取得します。
pnir = SleipnirAPI.new
ini = pnir.profile("CloseURL.ini")
ini.get_string("ClosedURL2", "URL0") #=> "http://hogehoge"
#section でこの ini ファイル内のセクションに対応する SleipnirAPI::Profile::Section オブジェクトを取得できます。
Instance Attribute Summary collapse
-
#default_opts ⇒ Object
readonly
#get_string などに指定するデフォルトの引数を取得します。 値は #profile から引き継いでいます。.
-
#name ⇒ Object
readonly
ini ファイル名を返します。 これは、SleipnirAPI::Profile#ini に指定した値をそのまま返します。 フルパスを得たい場合は #path を利用してください。.
-
#profile ⇒ Object
readonly
SleipnirAPI::Profile オブジェクトを返します。.
Instance Method Summary collapse
-
#check_writable ⇒ Object
script.ini でない場合は SleipnirAPI::Profile::ReadOnlyError を raise します。.
-
#delete(section, key) ⇒ Object
<ini_dir>\script.ini から指定されたキーを削除します。.
-
#get_int(section, key, opts = nil) ⇒ Object
call-seq: get_int(section, key) get_int(section, key, :default => -1) get_int(section, key, :cipher => true) get_int(section, key, :cipher => true, :default => -1).
-
#get_string(section, key, opts = nil) ⇒ Object
call-seq: get_string(section, key) get_string(section, key, :default => “default value”) get_string(section, key, :cipher => true) get_string(section, key, :cipher => true, :default => “default value”).
-
#initialize(profile, name, default_opts = nil) ⇒ Ini
constructor
A new instance of Ini.
-
#list(section, keyfmt, countkey = "Count", opts = nil, &block) ⇒ Object
call-seq: list(section, keyfmt, countkey=“Count”) list(section, keyfmt, countkey=“Count”, :default => “default value”) list(section, keyfmt, countkey=“Count”, :cipher => true) list(section, keyfmt, countkey=“Count”, :cipher => true, :default => “default value”).
-
#method_missing(mid, *args, &block) ⇒ Object
メソッド名をセクション名とみなして SleipnirAPI::Profile::Section オブジェクトを返します。.
-
#path ⇒ Object
(also: #to_s)
この ini ファイルのフルパスを返します。.
-
#read_only? ⇒ Boolean
<ini_dir>\script.ini 以外なら true を返します。.
-
#script_ini? ⇒ Boolean
<ini_dir>\script.ini なら true を返します。.
-
#section(name, opts = nil) ⇒ Object
指定されたセクションを操作する SleipnirAPI::Profile::Section オブジェクトを返します。.
-
#write_int(section, key, data, opts = nil) ⇒ Object
call-seq: write_int(section, key, data) write_int(section, key, data, :cipher => true).
-
#write_string(section, key, data, opts = nil) ⇒ Object
call-seq: write_string(section, key, data) write_string(section, key, data, :cipher => true).
Methods inherited from ProfileElement
Methods included from DataUtil
Methods included from OptionArgument
Methods included from OptionUtil
Constructor Details
#initialize(profile, name, default_opts = nil) ⇒ Ini
Returns a new instance of Ini.
31 32 33 34 35 |
# File 'lib/sleipnir_api/profile/ini.rb', line 31 def initialize(profile, name, default_opts = nil) super(nil, default_opts) @profile = profile @name = (name == "" ? nil : name) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mid, *args, &block) ⇒ Object
メソッド名をセクション名とみなして SleipnirAPI::Profile::Section オブジェクトを返します。
pnir = SleipnirAPI.connect
proxy = pnir.profile.Proxy(:default => 123)
sec = proxy.Proxy
sec.get_int("Count")
See Also: #section
170 171 172 |
# File 'lib/sleipnir_api/profile/ini.rb', line 170 def method_missing(mid, *args, &block) section(mid.to_s, *args, &block) end |
Instance Attribute Details
#default_opts ⇒ Object (readonly)
#get_string などに指定するデフォルトの引数を取得します。値は #profile から引き継いでいます。
29 30 31 |
# File 'lib/sleipnir_api/profile/ini.rb', line 29 def default_opts @default_opts end |
#name ⇒ Object (readonly)
ini ファイル名を返します。これは、SleipnirAPI::Profile#ini に指定した値をそのまま返します。フルパスを得たい場合は #path を利用してください。
25 26 27 |
# File 'lib/sleipnir_api/profile/ini.rb', line 25 def name @name end |
#profile ⇒ Object (readonly)
SleipnirAPI::Profile オブジェクトを返します。
20 21 22 |
# File 'lib/sleipnir_api/profile/ini.rb', line 20 def profile @profile end |
Instance Method Details
#check_writable ⇒ Object
script.ini でない場合は SleipnirAPI::Profile::ReadOnlyError を raise します。
123 124 125 |
# File 'lib/sleipnir_api/profile/ini.rb', line 123 def check_writable raise ReadOnlyError, "`#{path}' is not writable" if read_only? end |
#delete(section, key) ⇒ Object
<ini_dir>\script.ini から指定されたキーを削除します。
script.ini でない場合は SleipnirAPI::Profile::ReadOnlyError を raise します。
See Also: SleipnirAPI::Profile#delete
117 118 119 120 |
# File 'lib/sleipnir_api/profile/ini.rb', line 117 def delete(section, key) check_writable @profile.delete(section, key) end |
#get_int(section, key, opts = nil) ⇒ Object
call-seq:
get_int(section, key)
get_int(section, key, :default => -1)
get_int(section, key, :cipher => true)
get_int(section, key, :cipher => true, :default => -1)
この ini ファイルから int 型データを読み込みます。
See Also: SleipnirAPI::Profile#get_int
78 79 80 |
# File 'lib/sleipnir_api/profile/ini.rb', line 78 def get_int(section, key, opts = nil) @profile.get_int(section, key, (opts)) end |
#get_string(section, key, opts = nil) ⇒ Object
call-seq:
get_string(section, key)
get_string(section, key, :default => "default value")
get_string(section, key, :cipher => true)
get_string(section, key, :cipher => true, :default => "default value")
この ini ファイルから string 型データを読み込みます。
See Also: SleipnirAPI::Profile#get_string
65 66 67 |
# File 'lib/sleipnir_api/profile/ini.rb', line 65 def get_string(section, key, opts = nil) @profile.get_string(section, key, (opts)) end |
#list(section, keyfmt, countkey = "Count", opts = nil, &block) ⇒ Object
call-seq:
list(section, keyfmt, countkey="Count")
list(section, keyfmt, countkey="Count", :default => "default value")
list(section, keyfmt, countkey="Count", :cipher => true)
list(section, keyfmt, countkey="Count", :cipher => true, :default => "default value")
この ini ファイルから連番キーのデータをすべて読み込み配列で返します。
例:
pnir = SleipnirAPI.connect
proxy_ini = pnir.profile.proxy
proxy_ini.list("Proxy", "Proxy0_Title")
See Also: SleipnirAPI::Profile#list
52 53 54 |
# File 'lib/sleipnir_api/profile/ini.rb', line 52 def list(section, keyfmt, countkey="Count", opts = nil, &block) @profile.list(section, keyfmt, countkey, (opts), &block) end |
#path ⇒ Object Also known as: to_s
この ini ファイルのフルパスを返します。
128 129 130 131 132 133 134 |
# File 'lib/sleipnir_api/profile/ini.rb', line 128 def path if script_ini? @profile.script_ini_path else @profile.(@name) end end |
#read_only? ⇒ Boolean
<ini_dir>\script.ini 以外なら true を返します。
146 147 148 |
# File 'lib/sleipnir_api/profile/ini.rb', line 146 def read_only? not script_ini? end |
#script_ini? ⇒ Boolean
<ini_dir>\script.ini なら true を返します。
138 139 140 141 142 143 |
# File 'lib/sleipnir_api/profile/ini.rb', line 138 def script_ini? return true if @name.nil? a = @profile.(@name) b = @profile.script_ini_path a.match(/\A#{Regexp.quote(b)}\z/i) ? true : false end |
#section(name, opts = nil) ⇒ Object
指定されたセクションを操作する SleipnirAPI::Profile::Section オブジェクトを返します。
pnir = SleipnirAPI.connect
proxy = pnir.profile.ini("Proxy.ini", :default => 123)
sec = proxy.section("Proxy")
sec.get_int("Count")
See Also: #method_missing
158 159 160 |
# File 'lib/sleipnir_api/profile/ini.rb', line 158 def section(name, opts = nil) Section.new(self, str(name), (opts)) end |
#write_int(section, key, data, opts = nil) ⇒ Object
call-seq:
write_int(section, key, data)
write_int(section, key, data, :cipher => true)
<ini_dir>\script.ini に int 型データを書き込みます。script.ini でない場合は SleipnirAPI::Profile::ReadOnlyError を raise します。
-
:cipherに true を指定すると暗号化してデータを書き込みます。
See Also: SleipnirAPI::Profile#write_int
107 108 109 110 |
# File 'lib/sleipnir_api/profile/ini.rb', line 107 def write_int(section, key, data, opts = nil) check_writable @profile.write_int(section, key, data, (opts)) end |
#write_string(section, key, data, opts = nil) ⇒ Object
call-seq:
write_string(section, key, data)
write_string(section, key, data, :cipher => true)
<ini_dir>\script.ini に string 型データを書き込みます。script.ini でない場合は SleipnirAPI::Profile::ReadOnlyError を raise します。
-
:cipherに true を指定すると暗号化してデータを書き込みます。
See Also: SleipnirAPI::Profile#write_string
92 93 94 95 |
# File 'lib/sleipnir_api/profile/ini.rb', line 92 def write_string(section, key, data, opts = nil) check_writable @profile.write_string(section, key, data, (opts)) end |