Module: AssLauncher::Support::ConnectionString

Included in:
File, Http, Server
Defined in:
lib/ass_launcher/support/connection_string.rb

Overview

Note:

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

Examples:

cs =  AssLauncher::Support::\
  ConnectionString.new('File="\\fileserver\accounting.ib"')
cs.is #-> :file
cs.is? :file #-> true
cs.usr = 'username'
cs.pwd = 'password'
cmd = "1civ8.exe enterprise #{cs.to_cmd}"
run_result = AssLauncher::Support::Shell.run_ass(cmd)

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

Instance Method Summary collapse

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

Parameters:

Returns:



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]

Examples:

parse 'Field="""Value"""' -> {field: '"Value"'}

Parameters:

Returns:

  • (Hash)


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

#fieldsObject

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

#isSymbol

Return type of connection string :file, :server, :http

Returns:

  • (Symbol)


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

Examples:

if cs.is? :file
  #do for connect to the file infobase
else
  raise "#{cs.is} unsupport
end

Parameters:

  • symbol (Symvol)

Returns:

  • (Boolean)


99
100
101
# File 'lib/ass_launcher/support/connection_string.rb', line 99

def is?(symbol)
  is == symbol
end

#required_fieldsObject

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_argsArray

Convert connection string to array of 1C:Enterprise parameters.

Returns:

  • (Array)

    of 1C:Enterprise CLI 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_cmdString

Convert connection string to string of 1C:Enterprise parameters like /N“usr” /P“pwd” etc. See #to_args

Returns:



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_hashObject



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