Module: AssLauncher::Support::ConnectionString
Overview
All connection string class have methods for get and set values of defined fields. Methods have name as fields but in downcase All fields defined for connection string class retutn #fields
Implement 1C connection string Mixin for connection string classes
Defined Under Namespace
Classes: Error, File, Http, ParseError, Server
Constant Summary collapse
- COMMON_FIELDS =
Commonn connection string fields
%w(Usr Pwd LicDstr prmod Locale Zn Uc)
- SERVER_FIELDS =
Fields for server-infobase
%w(Srvr Ref)
- FILE_FIELDS =
Fields for file-infobase
%w(File)
- HTTP_FIELDS =
Fields for infobase published on http server
%w(Ws)
- HTTP_WEB_AUTH_FIELDS =
%w(Wsn Wsp)
- PROXY_FIELDS =
Proxy fields for accsess to infobase published on http server via proxy
%w(WspAuto WspSrv WspPort WspUser WspPwd)
- IB_MAKER_FIELDS =
Fields for makes server-infobase
%w(DBMS DBSrvr DB DBUID DBPwd SQLYOffs CrSQLDB SchJobDn SUsr SPwd DBFormat DBPageSize)
- DBMS_VALUES =
Values for DBMS field
%w(MSSQLServer PostgreSQL IBMDB2 OracleDatabase)
- DB_PAGE_SIZE_VALUES =
Values for DBPageSize
%w{4k , 8k, 16k, 32k, 64k}
- DB_FORMAT_VALUES =
Values for DBFormat
%w{8.2.14 8.3.8}
Class Method Summary collapse
- .included(base) ⇒ Object
-
.new(connstr) ⇒ Server | File | Http
Analyzes connect string and build suitable class.
-
.parse(connstr) ⇒ Hash
Parse connect string into hash.
Instance Method Summary collapse
-
#fields ⇒ Object
All fields defined for connection string.
-
#is ⇒ Symbol
Return type of connection string :file, :server, :http.
-
#is?(symbol) ⇒ Boolean
Check connection string for type :file, :server, :http.
-
#required_fields ⇒ Object
Fields required for new instance of connection string.
-
#to_args ⇒ Array
Convert connection string to array of 1C:Enterprise parameters.
-
#to_cmd ⇒ String
Convert connection string to string of 1C:Enterprise parameters like /N“usr” /P“pwd” etc.
- #to_hash ⇒ Object
- #to_s(only_fields = nil) ⇒ Object
Class Method Details
.included(base) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/ass_launcher/support/connection_string.rb', line 162 def self.included(base) base.fields.each do |f| base.send(:attr_reader, f.downcase.to_sym) unless\ base.instance_methods.include? f.downcase.to_sym base.send(:attr_writer, f.downcase.to_sym) unless\ base.instance_methods.include? "#{f.downcase}=".to_sym end end |
.new(connstr) ⇒ Server | File | Http
Analyzes connect string and build suitable class
49 50 51 52 53 54 55 56 57 |
# File 'lib/ass_launcher/support/connection_string.rb', line 49 def self.new(connstr) case connstr when /(\W|\A)File\s*=\s*"/i then File.new(parse(connstr)) when /(\W|\A)Srvr\s*=\s*"/i then Server.new(parse(connstr)) when /(\W|\A)Ws\s*=\s*"/i then Http.new(parse(connstr)) else fail ParseError, "Uncknown connstr `#{connstr}'" end end |
.parse(connstr) ⇒ Hash
Parse connect string into hash. Connect string have format:
'Field1="Value";Field2="Value";'
Quotes ‘ “ ’ in value of field escape as doble quote ‘ ”“ ’. Fields name convert to downcase [Symbol]
68 69 70 71 72 73 74 75 |
# File 'lib/ass_launcher/support/connection_string.rb', line 68 def self.parse(connstr) res = {} connstr.split(';').each do |str| str.strip! res.merge!(parse_key_value str) unless str.empty? end res end |
Instance Method Details
#fields ⇒ Object
All fields defined for connection string
158 159 160 |
# File 'lib/ass_launcher/support/connection_string.rb', line 158 def fields self.class.fields end |
#is ⇒ Symbol
Return type of connection string :file, :server, :http
87 88 89 |
# File 'lib/ass_launcher/support/connection_string.rb', line 87 def is self.class.name.split('::').last.downcase.to_sym end |
#is?(symbol) ⇒ Boolean
Check connection string for type :file, :server, :http
99 100 101 |
# File 'lib/ass_launcher/support/connection_string.rb', line 99 def is?(symbol) is == symbol end |
#required_fields ⇒ Object
Fields required for new instance of connection string
153 154 155 |
# File 'lib/ass_launcher/support/connection_string.rb', line 153 def required_fields self.class.required_fields end |
#to_args ⇒ Array
Convert connection string to array of 1C:Enterprise parameters.
122 123 124 |
# File 'lib/ass_launcher/support/connection_string.rb', line 122 def to_args to_args_common + to_args_private end |
#to_cmd ⇒ String
Convert connection string to string of 1C:Enterprise parameters like /N“usr” /P“pwd” etc. See #to_args
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ass_launcher/support/connection_string.rb', line 140 def to_cmd r = '' args = to_args args.each_with_index do |v, i| next unless i.even? r << v r << "\"#{args[i + 1]}\"" unless args[i + 1].to_s.empty? r << ' ' end r end |
#to_hash ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/ass_launcher/support/connection_string.rb', line 103 def to_hash result = {} fields.each do |f| result[f.downcase.to_sym] = get_property(f) end result end |
#to_s(only_fields = nil) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/ass_launcher/support/connection_string.rb', line 111 def to_s(only_fields = nil) only_fields ||= fields result = '' only_fields.each do |f| result << "#{prop_to_s(f)};" unless get_property(f).to_s.empty? end result end |