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)
- 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)
- DBMS_VALUES =
Values for DBMS field
%w(MSSQLServer PostgreSQL IBMDB2 OracleDatabase)
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
154 155 156 157 158 159 160 161 |
# File 'lib/ass_launcher/support/connection_string.rb', line 154 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
41 42 43 44 45 46 47 48 49 |
# File 'lib/ass_launcher/support/connection_string.rb', line 41 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]
60 61 62 63 64 65 66 67 |
# File 'lib/ass_launcher/support/connection_string.rb', line 60 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
150 151 152 |
# File 'lib/ass_launcher/support/connection_string.rb', line 150 def fields self.class.fields end |
#is ⇒ Symbol
Return type of connection string :file, :server, :http
79 80 81 |
# File 'lib/ass_launcher/support/connection_string.rb', line 79 def is self.class.name.split('::').last.downcase.to_sym end |
#is?(symbol) ⇒ Boolean
Check connection string for type :file, :server, :http
91 92 93 |
# File 'lib/ass_launcher/support/connection_string.rb', line 91 def is?(symbol) is == symbol end |
#required_fields ⇒ Object
Fields required for new instance of connection string
145 146 147 |
# File 'lib/ass_launcher/support/connection_string.rb', line 145 def required_fields self.class.required_fields end |
#to_args ⇒ Array
Convert connection string to array of 1C:Enterprise parameters.
114 115 116 |
# File 'lib/ass_launcher/support/connection_string.rb', line 114 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
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ass_launcher/support/connection_string.rb', line 132 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
95 96 97 98 99 100 101 |
# File 'lib/ass_launcher/support/connection_string.rb', line 95 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
103 104 105 106 107 108 109 110 |
# File 'lib/ass_launcher/support/connection_string.rb', line 103 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 |