rober 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e40d5ef421f8979c4febfd6c758f0f835149d96f
4
- data.tar.gz: 0896db77b4748e3667914bb0014b57a833745c32
2
+ SHA256:
3
+ metadata.gz: 896a3a288ed0ac41afb2397cfe864ac914ea5b05a3dcf2d108af1899329c98d1
4
+ data.tar.gz: 80f50a15cc69547672b8041cf0da17f8922c081afbd42039355f6ad42f7ba329
5
5
  SHA512:
6
- metadata.gz: cd01f23fbbb7c9280bbe4e67124e5b75fa3fa13dc09ab45b2149733e812941682f870779601a55963db7a6d633edee229e5e45b172cd6ee0d677a60214201e1d
7
- data.tar.gz: fcf3d1d0d0460a22e14b88813bc2b5bb4c19c71cc5a2f8fc346fd0c85e8e56bc304e42b77be0a6c03bab586b1632f5e67879591383f00dde31a4aa012059501e
6
+ metadata.gz: 2861a9afa7fa7e066844199a6b620276d4801095e8d172c178ba706a8caa86ce5222af2c7b27a1c02b3c38571a722260046ff2c656ff2542cc3476b85108d7e4
7
+ data.tar.gz: 4f682206b63f6b6d5aa187179549c1cfc1f7bb3f7b7e4a3df6b7339f7bc034d727fa31ae332c6b3557c462c0a9bd7cae858c8609a371b6adab2a28f4315f4396
data/README.md CHANGED
@@ -30,6 +30,9 @@ TODO: Write usage instructions here
30
30
 
31
31
  ## Changes
32
32
 
33
+ 2018-01-10 0.0.3
34
+ add dbm file for pgmodeler
35
+
33
36
  2014-01-06 0.0.2
34
37
  modify CRLF to "and charp 10 semicolon"
35
38
 
@@ -3,6 +3,16 @@ require 'nokogiri'
3
3
  module Rober
4
4
  class Reader
5
5
  def self.read(path)
6
+ if path.end_with?("edm")
7
+ read_edm(path)
8
+ elsif path.end_with?("dbm")
9
+ read_dbm(path)
10
+ else
11
+ {}
12
+ end
13
+ end
14
+
15
+ def self.read_edm(path)
6
16
  doc = Nokogiri::XML(file_read(path))
7
17
  entities = []
8
18
  doc.xpath('/ERD/ENTITY').each do |it|
@@ -31,5 +41,38 @@ module Rober
31
41
  res = File.read(path)
32
42
  res.gsub(/\r\n/, "
")
33
43
  end
44
+
45
+ def self.read_dbm(path)
46
+ doc = Nokogiri::XML(File.read(path))
47
+ entities = []
48
+ doc.xpath('/dbmodel/table').each do |it|
49
+
50
+ entity = Rober::Entity.new
51
+ entity.logical_name = it[:name]
52
+ entity.physical_name = it[:name]
53
+ list = it.xpath('./comment/text()')
54
+ entity.comment = list.first.content unless list.empty?
55
+ list = it.xpath('constraint[@type="pk-constr"]')
56
+ pk_ary = []
57
+ unless list.empty?
58
+ pk_ary = list.first.xpath('columns').map{|col| col[:names]}
59
+ end
60
+ it.xpath('column').each do |attr|
61
+ type_tag = attr.xpath('./type').first
62
+ attribute = Rober::Attribute.new
63
+ attribute.logical_name = attr[:name]
64
+ attribute.physical_name = attr[:name]
65
+ attribute.datatype = type_tag[:name]
66
+ attribute.length = type_tag[:length]
67
+ attribute.scale = type_tag[:precision] || '0'
68
+ attribute.null = attr[:"not-null"] == 'true' ? '1' : '0'
69
+ attribute.def = attr[:"default-value"] || ''
70
+ attribute.pk = pk_ary.include?(attribute.physical_name) ? '1' : '0'
71
+ entity.add(attribute)
72
+ end
73
+ entities << entity
74
+ end
75
+ {entities: entities}
76
+ end
34
77
  end
35
78
  end
@@ -1,3 +1,3 @@
1
1
  module Rober
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_dependency "nokogiri"
@@ -2,15 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  describe Rober do
4
4
  it 'should have a version number' do
5
- Rober::VERSION.should_not be_nil
5
+ expect(Rober::VERSION).to be
6
6
  end
7
7
 
8
8
  it 'read edm' do
9
- ober = Rober::Reader.read(FILE)
9
+ ober = Rober::Reader.read(FILE_EDM)
10
10
  entities = ober[:entities]
11
11
  expect(entities.size).to eq(2)
12
12
  expect(entities[0].attributes.size).to eq(3)
13
13
  expect(entities[1].attributes.size).to eq(2)
14
14
  expect(entities[0].comment).to match(/\n/)
15
15
  end
16
+
17
+ it 'read dbm' do
18
+ ober = Rober::Reader.read(FILE_DBM)
19
+ entities = ober[:entities]
20
+ expect(entities.size).to eq(2)
21
+ expect(entities[0].attributes.size).to eq(3)
22
+ expect(entities[1].attributes.size).to eq(4)
23
+ expect(entities[0].comment).to eq("aaa\nbbb")
24
+ end
16
25
  end
@@ -1,3 +1,4 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'rober'
3
- FILE = 'spec/test.edm'
3
+ FILE_EDM = 'spec/test.edm'
4
+ FILE_DBM = 'spec/test.dbm'
@@ -0,0 +1,55 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ CAUTION: Do not modify this file unless you know what you are doing.
4
+ Unexpected results may occur if the code is changed deliberately.
5
+ -->
6
+ <dbmodel pgmodeler-ver="0.9.1-beta" last-position="0,0" last-zoom="1"
7
+ default-schema="public" default-owner="postgres">
8
+ <database name="test">
9
+ </database>
10
+
11
+ <schema name="public" fill-color="#e1e1e1" sql-disabled="true">
12
+ </schema>
13
+
14
+ <table name="companies">
15
+ <schema name="public"/>
16
+ <role name="postgres"/>
17
+ <comment><![CDATA[aaa
18
+ bbb]]></comment>
19
+ <position x="240" y="140"/>
20
+ <column name="uuid" not-null="true" default-value="gen_random_uuid()">
21
+ <type name="uuid" length="0"/>
22
+ </column>
23
+ <column name="name" not-null="true" default-value="''">
24
+ <type name="text" length="0"/>
25
+ </column>
26
+ <column name="created_at" not-null="true" default-value="current_timestamp">
27
+ <type name="timestamptz" length="0"/>
28
+ </column>
29
+ <constraint name="companies_pk" type="pk-constr" table="public.companies">
30
+ <columns names="uuid" ref-type="src-columns"/>
31
+ </constraint>
32
+ </table>
33
+
34
+ <table name="users">
35
+ <schema name="public"/>
36
+ <role name="postgres"/>
37
+ <position x="480" y="140"/>
38
+ <column name="uuid" not-null="true" default-value="gen_random_uuid()">
39
+ <type name="uuid" length="0"/>
40
+ </column>
41
+ <column name="name" not-null="true" default-value="''">
42
+ <type name="text" length="0"/>
43
+ </column>
44
+ <column name="created_at" not-null="true" default-value="current_timestamp">
45
+ <type name="timestamptz" length="0"/>
46
+ </column>
47
+ <column name="company_uuid">
48
+ <type name="uuid" length="0"/>
49
+ </column>
50
+ <constraint name="users_pk" type="pk-constr" table="public.users">
51
+ <columns names="uuid" ref-type="src-columns"/>
52
+ </constraint>
53
+ </table>
54
+
55
+ </dbmodel>
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rober
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - aoyagikouhei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2019-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +88,7 @@ files:
88
88
  - rober.gemspec
89
89
  - spec/rober_spec.rb
90
90
  - spec/spec_helper.rb
91
+ - spec/test.dbm
91
92
  - spec/test.edm
92
93
  homepage: ''
93
94
  licenses:
@@ -108,12 +109,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  - !ruby/object:Gem::Version
109
110
  version: '0'
110
111
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.2.0
112
+ rubygems_version: 3.0.2
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: ober reader
116
116
  test_files:
117
117
  - spec/rober_spec.rb
118
118
  - spec/spec_helper.rb
119
+ - spec/test.dbm
119
120
  - spec/test.edm