Class: AssMaintainer::InfoBase

Inherits:
Object
  • Object
show all
Extended by:
AssLauncher::Api, Forwardable
Defined in:
lib/ass_maintainer/info_base.rb,
lib/ass_maintainer/info_base/cfg.rb,
lib/ass_maintainer/info_base/config.rb,
lib/ass_maintainer/info_base/file_ib.rb,
lib/ass_maintainer/info_base/version.rb,
lib/ass_maintainer/info_base/server_ib.rb,
lib/ass_maintainer/info_base/interfaces.rb,
lib/ass_maintainer/info_base/default_maker.rb,
lib/ass_maintainer/info_base/server_ib/helpers.rb

Overview

Class for manipulate with 1C:Enterprise application instance aka information base or infobase

Instances of this class have dinamicly generated interfaece

1C:Enterprise application may be deployed as file (aka file infobase) or on a 1C:Enterprise server (aka server infobase). In the #initialize instance of this class will be extended suitable module:

  • server infobase instance will be extend module ServerIb

  • file infobase instance will be exten module FileIb

Both instance type inherits methods from Interfaces::InfoBaseWrapper

All instances get methods wrappers for access to #options see InfoBase.build_options_wrapper

Defined Under Namespace

Modules: FileIb, Interfaces, ServerIb Classes: AbstractCfg, Cfg, Config, DbCfg, DefaultMaker, MethodDenied

Constant Summary collapse

DEFAULT_SAGENT_PORT =

Deafult port for connect to 1C:Enterprise serever agent

'1540'
HOOKS =

Hooks before and after make and remove infobase. Hooks may be passed as options or seted later see #add_hook

{
  before_make: ->(ib) {},
  after_make: ->(ib) {},
  before_rm: ->(ib) {},
  after_rm: ->(ib) {}
}
WORKERS =

On default for make and remove infobase uses DefaultMaker and FileIb::FileBaseDestroyer or ServerIb::ServerBaseDestroyer but we can pass custom maker and destroyer as #options. Maker and destroyer must implements Interfaces::IbMaker and Interfaces::IbDestroyer

{
  maker: nil,
  destroyer: nil
}
ARGUMENTS =
  • :latform_require Required 1C:Enterprise version

  • :agent_host Host name of 1C:Enterprise server agent

  • :agent_port TCP port of 1C:Enterprise server agent on default DEFAULT_SAGENT_PORT

  • :agent_usr Admin for 1C:Enterprise server agent

  • :agent_pwd Admin password for 1C:Enterprise server agent

  • :laster_usr Admin for 1C:Enterprise claster. See ServerIb#claster_usr

  • :laster_pwd Pasword Admin for 1C:Enterprise claster. See ServerIb#claster_pwd

  • :nlock_code Code for connect to locked infobase aka “/UC” parameter

{
  platform_require: nil,
  sagent_host: nil,
  sagent_port: nil,
  sagent_usr: nil,
  sagent_pwd: nil,
  claster_usr: nil,
  claster_pwd: nil,
  unlock_code: nil
}
OPTIONS =
(ARGUMENTS.merge HOOKS).merge WORKERS
ASS_PLATFORM_REQUIRE =
ENV['ASS_PLATFORM_REQUIRE'] || '> 0'
VERSION =
'0.1.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, connection_string, read_only = true, **options) {|_self| ... } ⇒ InfoBase

Returns a new instance of InfoBase.

Parameters:

  • name (String)

    name of infobase

  • connection_string (String AssLauncher::Support::ConnectionString)
  • read_only (true false) (defaults to: true)

    infobse is read only or not

  • options (Hash)

    see OPTIONS

Yields:

  • (_self)

Yield Parameters:



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/ass_maintainer/info_base.rb', line 116

def initialize(name, connection_string, read_only = true, **options)
  @name = name
  @connection_string = self.class.cs(connection_string.to_s)
  @read_only = read_only
  @options = OPTIONS.merge(options)
  case self.connection_string.is
  when :file then extend FileIb
  when :server then extend ServerIb
  else fail ArgumentError
  end
  yield self if block_given?
end

Instance Attribute Details

#connection_stringObject (readonly)

see #initialize connection_string



104
105
106
# File 'lib/ass_maintainer/info_base.rb', line 104

def connection_string
  @connection_string
end

#nameObject (readonly)

see #initialize name



102
103
104
# File 'lib/ass_maintainer/info_base.rb', line 102

def name
  @name
end

#optionsObject (readonly)

see #initialize options



106
107
108
# File 'lib/ass_maintainer/info_base.rb', line 106

def options
  @options
end

#read_onlyObject (readonly) Also known as: read_only?

InfoBase is read only destructive methods will be fail with MethodDenied error



109
110
111
# File 'lib/ass_maintainer/info_base.rb', line 109

def read_only
  @read_only
end

Class Method Details

.build_options_wrapperObject

Dinamicaly builds of options wrappers



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ass_maintainer/info_base.rb', line 85

def self.build_options_wrapper
  OPTIONS.each_key do |key|
    next if WORKERS.keys.include? key
    define_method key do
      options[key]
    end

    next if HOOKS.keys.include? key
    define_method "#{key}=".to_sym do |arg|
      options[key] = arg
    end
  end
end

.configConfig

Get settings

Returns:



24
25
26
# File 'lib/ass_maintainer/info_base/config.rb', line 24

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Make settings

Yields:



18
19
20
# File 'lib/ass_maintainer/info_base/config.rb', line 18

def self.configure
  yield config
end

Instance Method Details

#add_hook(hook, &block) ⇒ Object

Add hook. In all hook whill be passed self

Parameters:

  • hook (Symbol)

    hook name

Raises:

  • (ArgumentError)

    if invalid hook name or not block given



132
133
134
135
136
137
# File 'lib/ass_maintainer/info_base.rb', line 132

def add_hook(hook, &block)
  fail ArgumentError, "Invalid hook `#{hook}'" unless\
    HOOKS.keys.include? hook
  fail ArgumentError, 'Block require' unless block_given?
  options[hook] = block
end

#cfgCfg nil

Returns instance for manipuate with databse configuration. If infobase not exists returns nil

Returns:



330
331
332
# File 'lib/ass_maintainer/info_base.rb', line 330

def cfg
  @cfg ||= Cfg.new(self) if exists?
end

#common_argsObject

Common arguments for all commands



293
294
295
296
297
298
# File 'lib/ass_maintainer/info_base.rb', line 293

def common_args
  r = []
  r += ['/L', locale] if locale
  r += ['/UC', unlock_code] if unlock_code
  r
end

#db_cfgDbase nil

Returns instance for manipuate with InfoBase database. If infobase not exists returns nil

Returns:

  • (Dbase nil)


322
323
324
# File 'lib/ass_maintainer/info_base.rb', line 322

def db_cfg
  @db_cfg ||= DbCfg.new(self) if exists?
end

#designer(&block) ⇒ AssLauncher::Support::Shell::Command

Build command for run designer block will be passed to arguments builder

Returns:

  • (AssLauncher::Support::Shell::Command)


266
267
268
# File 'lib/ass_maintainer/info_base.rb', line 266

def designer(&block)
  command(:thick, :designer, &block)
end

#dump(path) ⇒ Object

Dump infobase to .dt file



301
302
303
304
305
306
# File 'lib/ass_maintainer/info_base.rb', line 301

def dump(path)
  designer do
    dumpIB path
  end.run.wait.result.verify!
  path
end

#enterprise(client, &block) ⇒ AssLauncher::Support::Shell::Command

Build command for run enterprise block will be passed to arguments builder

Parameters:

  • client (Symbol)

    :thin or thick client

Returns:

  • (AssLauncher::Support::Shell::Command)


274
275
276
# File 'lib/ass_maintainer/info_base.rb', line 274

def enterprise(client, &block)
  command(client, :enterprise, &block)
end

#isSymbol

Returns type of infobase

Returns:

  • (Symbol)

    :file or :server



191
192
193
# File 'lib/ass_maintainer/info_base.rb', line 191

def is
  connection_string.is
end

#is?(type) ⇒ Boolean

Check type of infobase

Parameters:

  • type (Symbol)

    :file or :server

Returns:

  • (Boolean)


197
198
199
# File 'lib/ass_maintainer/info_base.rb', line 197

def is?(type)
  connection_string.is?(type)
end

#localeString

Get locale

Returns:

  • (String)


220
221
222
# File 'lib/ass_maintainer/info_base.rb', line 220

def locale
  connection_string.locale
end

#locale=(l) ⇒ Object

Set locale

Parameters:

  • l (String)

    locale code en, ru etc



214
215
216
# File 'lib/ass_maintainer/info_base.rb', line 214

def locale=(l)
  connection_string.locale = l
end

#makeObject

Make new empty infobase wrpped in before_make and after_make hooks

Raises:



153
154
155
156
# File 'lib/ass_maintainer/info_base.rb', line 153

def make
  make_infobase! unless exists?
  self
end

#ole(type) ⇒ Object

Get ole connector specified in type parameter

Parameters:

  • type (Symbol)

    see AssLauncher::Api#ole



249
250
251
# File 'lib/ass_maintainer/info_base.rb', line 249

def ole(type)
  self.class.ole(type, ole_requirement)
end

#platform_requireString

Requrement 1C version

Returns:

  • (String)


141
142
143
# File 'lib/ass_maintainer/info_base.rb', line 141

def platform_require
  options[:platform_require] || self.class.config.platform_require
end

#pwdString

User password

Returns:

  • (String)


231
232
233
# File 'lib/ass_maintainer/info_base.rb', line 231

def pwd
  connection_string.pwd
end

#pwd=(password) ⇒ Object

Set user password



225
226
227
# File 'lib/ass_maintainer/info_base.rb', line 225

def pwd=(password)
  connection_string.pwd = password
end

#rebuild!(sure = :no) ⇒ Object

Rebuild infobse first call #rm! second call #make

Raises:



147
148
149
150
# File 'lib/ass_maintainer/info_base.rb', line 147

def rebuild!(sure = :no)
  rm! sure
  make
end

#restore!(path) ⇒ Object

Restore infobase from .dt file

Raises:



310
311
312
313
314
315
316
# File 'lib/ass_maintainer/info_base.rb', line 310

def restore!(path)
  fail MethodDenied, :restore! if read_only?
  designer do
    restoreIB path
  end.run.wait.result.verify!
  path
end

#rm!(sure = :no) ⇒ Object

Remove infobase wrpped in before_rm and after_rm hooks

Raises:



171
172
173
174
175
176
# File 'lib/ass_maintainer/info_base.rb', line 171

def rm!(sure = :no)
  fail 'If you are sure pass :yes value' unless sure == :yes
  return unless exists?
  rm_infobase!
  nil
end

#thickAssLauncher::Enterprise::BinaryWrapper::ThickClient

Returns:

  • (AssLauncher::Enterprise::BinaryWrapper::ThickClient)


236
237
238
239
# File 'lib/ass_maintainer/info_base.rb', line 236

def thick
  self.class.thicks(platform_require).last ||
    fail("Platform 1C #{platform_require} not found")
end

#thinAssLauncher::Enterprise::BinaryWrapper::ThinClient

Returns:

  • (AssLauncher::Enterprise::BinaryWrapper::ThinClient)


242
243
244
245
# File 'lib/ass_maintainer/info_base.rb', line 242

def thin
  self.class.thins(platform_require).last ||
    fail("Platform 1C #{platform_require} not found")
end

#usrString

User name

Returns:

  • (String)


208
209
210
# File 'lib/ass_maintainer/info_base.rb', line 208

def usr
  connection_string.usr
end

#usr=(user_name) ⇒ Object

Set user name



202
203
204
# File 'lib/ass_maintainer/info_base.rb', line 202

def usr=(user_name)
  connection_string.usr = user_name
end