s41c 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -6,8 +6,8 @@ TCP-socket-сервер и клиент для платформы "1С:Пред
6
6
 
7
7
  ### Системные требования
8
8
 
9
- * Microsoft Windows семейства NT (32bit)
10
- * 1С:Предприятие v7
9
+ * Microsoft Windows семейства NT (только для сервера)
10
+ * 1С:Предприятие v7 (только для сервера)
11
11
  * [Ruby](http://rubyinstaller.org/downloads/) 1.9.3
12
12
 
13
13
  ### Установка
@@ -50,7 +50,7 @@ TCP-socket-сервер и клиент для платформы "1С:Пред
50
50
 
51
51
  При подключении можно указать хост и порт сервера (если не указаны, будут
52
52
  использоваться localhost:1421), а также данные для авторизации. После
53
- подключения на сервер передаётся руби-код в виде строки, который и выполняет все,
53
+ подключения на сервер передаётся руби-код, который и выполняет все,
54
54
  что нам нужно
55
55
 
56
56
  require 's41c'
@@ -58,7 +58,7 @@ TCP-socket-сервер и клиент для платформы "1С:Пред
58
58
  client = S41C::Client.new('127.0.0.1', 2000)
59
59
  client.login('username', 'password')
60
60
 
61
- response = client.eval %{
61
+ response = client.request do
62
62
 
63
63
  spr = @ole.CreateObject('Справочник.Товары')
64
64
 
@@ -71,7 +71,7 @@ TCP-socket-сервер и клиент для платформы "1С:Пред
71
71
 
72
72
  to_utf8(result)
73
73
 
74
- }
74
+ end
75
75
 
76
76
  puts response
77
77
  client.disconnect
data/lib/s41c/client.rb CHANGED
@@ -8,6 +8,7 @@ module S41C
8
8
 
9
9
  def initialize(host='localhost', port=1421)
10
10
  require 'net/telnet'
11
+ require 's41c/parser'
11
12
 
12
13
  @host, @port = host, port
13
14
  @prompt = /^\+OK/n
@@ -26,10 +27,6 @@ module S41C
26
27
  @errors
27
28
  end # errors
28
29
 
29
- def connect(options)
30
- cmd "connect\0#{options}"
31
- end # connect
32
-
33
30
  def ping
34
31
  cmd "ping"
35
32
  end # ping
@@ -42,6 +39,11 @@ module S41C
42
39
  cmd "shutdown"
43
40
  end # shutdown
44
41
 
42
+ def request(&block)
43
+ code = S41C::Parser.new(block).parse
44
+ self.eval code
45
+ end # request
46
+
45
47
  def eval(code)
46
48
  cmd "eval\0\n#{code}\nend_of_code"
47
49
  end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ module S41C
4
+
5
+ class Parser
6
+
7
+ BLOCK_BEGINNERS = /module|class|def|begin|do|case|if|unless|{/
8
+ BLOCK_ENDERS = /end|}/
9
+
10
+ def initialize(block)
11
+ sl = block.source_location
12
+ @file, @start_line = sl.first, (sl.last)
13
+
14
+ if @file[/\(irb\)/]
15
+ @lines = IRB.CurrentContext.io.line(0..-1)
16
+ else
17
+ f = File.open(@file, 'r')
18
+ @lines = f.lines.to_a
19
+ f.close
20
+ @start_line -= 1
21
+ end # if
22
+
23
+ end # new
24
+
25
+ def parse
26
+ raw = @lines[@start_line..-1]
27
+ depth = 0
28
+ @finish_line = @start_line
29
+
30
+ raw.each_with_index do |line, index|
31
+
32
+ depth += 1 if line[BLOCK_BEGINNERS]
33
+ depth -= 1 if line[BLOCK_ENDERS]
34
+
35
+ if depth == 0
36
+ @finish_line = index
37
+ break
38
+ end #if
39
+
40
+ end # each
41
+
42
+ block = raw[0..@finish_line]
43
+
44
+ block.first.sub!(/^.*#{BLOCK_BEGINNERS}/, '')
45
+ block.last.sub!(/#{BLOCK_ENDERS}.*$/, '')
46
+
47
+ block.join
48
+ end # parse
49
+
50
+ end # Parser
51
+
52
+ end # S41C
data/lib/s41c/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module S41C
2
2
 
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
 
5
5
  end # S41C
data/s41c-0.0.4.gem ADDED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s41c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-24 00:00:00.000000000 Z
12
+ date: 2012-03-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: TCP-socket сервер и клиент для платформы "1С:Предприятие"
15
15
  email:
@@ -23,10 +23,12 @@ files:
23
23
  - README.md
24
24
  - lib/s41c/sandbox.rb
25
25
  - lib/s41c/version.rb
26
+ - lib/s41c/parser.rb
26
27
  - lib/s41c/utils.rb
27
28
  - lib/s41c/server.rb
28
29
  - lib/s41c/client.rb
29
30
  - lib/s41c.rb
31
+ - s41c-0.0.4.gem
30
32
  - Gemfile
31
33
  - Rakefile
32
34
  homepage: https://github.com/dancingbytes/s41c