CapicuaGenMelchior 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e373a025deb9f000b35eecfc2c55f9652a3921a
4
+ data.tar.gz: 9d93b01330c2273a09ed369b4a0c69aa68432354
5
+ SHA512:
6
+ metadata.gz: c068e1e1535452d965bac8156deaf168397f8a727cb16246ef8bc5de16942f88e706270e72d450998447576cfaf9fb3380e5629aece7d13d7ae4409354811936
7
+ data.tar.gz: e02f3a81d576c5e75fa4493a8a0f2e9137047758ec6a2fa32923acc26059a7f380f83c593f3f1016dfede456eff798f177939896ddf8a666678c9e252ef639b6
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
11
+ /*.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jbautista@bansi.com.mx. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
@@ -0,0 +1,64 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'CapicuaGenMelchior/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "CapicuaGenMelchior"
8
+ spec.version = CapicuaGenMelchior::VERSION
9
+ spec.authors = ["José Luis Bautista Martín"]
10
+ spec.email = ["joseluisbautista@gmail.com"]
11
+ spec.date = Date.today.to_s
12
+
13
+
14
+ spec.summary = %q{CapicuaGen es un software que ayuda a la creación automática de
15
+ sistemas empresariales a través de la definición y ensamblado de
16
+ diversos generadores de características. Melchior es un conjunto de
17
+ generadores de caracteristicas de ejemplo pertenecientes a CapicuaGen
18
+ que se ocupa entre otras cosas de definir las clase para manejar entidades.
19
+ =end
20
+ }
21
+ spec.description = %q{CapicuaGen
22
+
23
+ CapicuaGen es un software que ayuda a la creación automática de
24
+ sistemas empresariales a través de la definición y ensamblado de
25
+ diversos generadores de características.
26
+
27
+ Melchior es un conjunto de generadores de caracteristicas de ejemplo pertenecientes a CapicuaGen
28
+ que se ocupa entre otras cosas de definir las clase para manejar entidades.
29
+
30
+
31
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
32
+ del 2016.
33
+
34
+ Puede modificar y distribuir este software, según le plazca, y usarlo
35
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
36
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
37
+ código fuente.
38
+
39
+ Este software es código libre, y se licencia bajo LGPL.
40
+
41
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
42
+ }
43
+
44
+ spec.homepage = "http://desdelashorasextras.blogspot.mx/"
45
+ spec.licenses = ['LGPL']
46
+
47
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
48
+ # delete this section to allow pushing this gem to any host.
49
+ if spec.respond_to?(:metadata)
50
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
51
+ else
52
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
53
+ end
54
+
55
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|\.idea)/}) }
56
+ spec.bindir = "exe"
57
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
58
+ spec.require_paths = ["lib"]
59
+
60
+ spec.add_development_dependency "bundler", "~> 1.11"
61
+ spec.add_development_dependency "rake", "~> 10.0"
62
+
63
+ spec.add_runtime_dependency 'CapicuaGen', '~> 0.0','>=0.0.1'
64
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in CapicuaGenMelchior.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ CapicuaGenMelchior (0.0.2)
5
+ CapicuaGen (~> 0.0, >= 0.0.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ CapicuaGen (0.0.1)
11
+ activesupport (~> 2.3, >= 2.3.18)
12
+ nokogiri (~> 1.6, >= 1.6.7)
13
+ uuidtools (~> 2.1, >= 2.1.5)
14
+ activesupport (2.3.18)
15
+ mini_portile2 (2.0.0)
16
+ nokogiri (1.6.7.2-x86-mingw32)
17
+ mini_portile2 (~> 2.0.0.rc2)
18
+ rake (10.4.2)
19
+ uuidtools (2.1.5)
20
+
21
+ PLATFORMS
22
+ x86-mingw32
23
+
24
+ DEPENDENCIES
25
+ CapicuaGenMelchior!
26
+ bundler (~> 1.11)
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # CapicuaGenMelchior
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/CapicuaGenMelchior`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'CapicuaGenMelchior'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install CapicuaGenMelchior
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/CapicuaGenMelchior. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "CapicuaGenMelchior/melchior"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,70 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ require_relative '../../../melchior'
23
+ require 'active_support/core_ext/object/blank'
24
+
25
+ module CapicuaGen::Melchior
26
+
27
+ # Define una campo de una entidad, puede estar ligado a un campo sql
28
+ class EntityFieldSchema
29
+
30
+ attr_accessor :name, :type, :size, :allow_null, :default_value, :primary_key, :sql_type, :identity, :sql_name
31
+
32
+ def initialize (values= {})
33
+
34
+ @name = values[:name]
35
+ @sql_name = values[:sql_name]
36
+ @type = values[:type]
37
+ @size = values[:size]
38
+ @allow_null = false
39
+ @allow_null = values[:allow_null] if values[:allow_null]
40
+ @default_value= values[:default_value]
41
+ @primary_key = false
42
+ @allow_null = values[:allow_null] if values[:allow_null]
43
+ @sql_type = values[:sql_type]
44
+ @identity = false
45
+ @identity = values[:@identity] if values[:identity]
46
+
47
+ # Ajusto el tipo
48
+ @type = @sql_type unless @type
49
+
50
+ # correguir_nombre
51
+ fix_name
52
+
53
+ end
54
+
55
+
56
+ protected
57
+ # Ajusta el nombre
58
+ def fix_name
59
+ return if @name
60
+ return unless @sql_name
61
+ @name= @sql_name.clone
62
+ /\[[^\]]+\]\.\[([^\]]+)\]/.match (@sql_name) { @name= $1 }
63
+ @name.gsub!("\"", '')
64
+ @name.gsub!("''", '')
65
+ @name.gsub!(" ", '')
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,64 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ module CapicuaGen::Melchior
23
+
24
+
25
+ # Clase para definir la estructura de una entidad, puede tener propiedades a su vez
26
+ class EntitySchema
27
+
28
+ attr_accessor :name, :fields, :sql_name
29
+
30
+ def initialize (values= {})
31
+ @name = values[:name]
32
+ @fields= values[:fields]
33
+ @fields= [] unless @fields
34
+
35
+ @sql_name= values[:sql_name]
36
+
37
+ # correguir_nombre
38
+ fix_name
39
+ end
40
+
41
+ # Deuelve los campos primarios
42
+ def primary_fields
43
+ return @fields.select { |field| field.primary_key }
44
+ end
45
+
46
+ def non_primary_fields
47
+ return @fields - primary_fields
48
+ end
49
+
50
+
51
+ protected
52
+ # Ajusta el nombre
53
+ def fix_name
54
+ return if @name
55
+ return unless @sql_name
56
+ @name= @sql_name.clone
57
+ /\[[^\]]+\]\.\[([^\]]+)\]/.match (@sql_name) { @name= $1 }
58
+ @name.gsub!("\"", '')
59
+ @name.gsub!("''", '')
60
+ @name.gsub!(" ", '')
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,83 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ require_relative '../../../melchior'
23
+ require 'active_support/core_ext/object/blank'
24
+ require 'uuidtools'
25
+
26
+ module CapicuaGen::Melchior
27
+
28
+ # Caracteristica que lee un archivo o string SQL y convierte las tablas leidas
29
+ # en entidades y lo expone para otras caracteristicas
30
+ # las caracteristicas pueden usar las entidades expuestas como clases o interfaces
31
+ class EntitySqlDataAccessFeature < CapicuaGen::Feature
32
+
33
+ public
34
+
35
+ # Inicializa la caracteristica
36
+ def initialize(values= {})
37
+ super(values) do end
38
+
39
+ # Configuro los tipos si estos no han sido configurados previamente
40
+ self.types= [:entity_sql_table] if self.types.blank?
41
+
42
+ @sql_string= []
43
+ @entities = []
44
+
45
+ #Ejecuto configuracion en bloque
46
+ yield self if block_given?
47
+ end
48
+
49
+
50
+ # Agrego una cadena SQL a las cadenas a analizar
51
+ def add_sql_string(*sql_strings)
52
+ # Reinicio las entidades presentes
53
+ @entities = []
54
+ # Agrego las cadenas
55
+ @sql_string+= sql_strings
56
+ end
57
+
58
+ # Agreo un archivo SQL
59
+ def add_sql_file(*sql_files)
60
+ sql_files.each do |f|
61
+ sql_string= File.open(f).read
62
+ add_sql_string(sql_string)
63
+ end
64
+ end
65
+
66
+ # Devuelvo las entidades
67
+ def get_entities
68
+
69
+ # Si tengo entidades ya creadas las devuelvo
70
+ @entities unless @entities.blank?
71
+
72
+ # Creo un parseador de entidades
73
+ parser = CapicuaGen::Melchior::SqlTableParse.new
74
+ @entities= parser.parse_string(*@sql_string)
75
+
76
+ return @entities
77
+
78
+ end
79
+
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,172 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ require_relative '../../../melchior'
23
+
24
+ module CapicuaGen::Melchior
25
+
26
+ # Analizador de tabla SQL segun su archivo de creacio (DLL)
27
+ # en este caso se hace a traves de un script exportado directamente de SQL Server
28
+ # de momento no es posible parsear un script realizado a mano, solo los exportados por
29
+ # MS SQL Server
30
+ class SqlTableParse
31
+
32
+ public
33
+ def initialize
34
+
35
+ end
36
+
37
+ # Parsea el string y devuelve las tablas encontradas
38
+ def parse_string(*sql_strings)
39
+
40
+ create_table= /(CREATE\s+TABLE[^\(]+)/mi
41
+
42
+ tables= []
43
+
44
+ sql_strings.each do |s|
45
+
46
+ sql_string= s.clone
47
+
48
+ while (sql_string.length>0) do
49
+
50
+ # Busco la opcion de crear una tabla
51
+ index= sql_string.index(create_table)
52
+
53
+ # Salida
54
+ break unless index
55
+
56
+ # Elimino dentro lo que hay antes del CREATE TABLE
57
+ sql_string = sql_string[index..sql_string.length]
58
+
59
+ # Obtengo el create table completo
60
+ table_found= find_create_table sql_string
61
+
62
+ if table_found
63
+ table= create_table table_found
64
+ tables.push table
65
+ end
66
+
67
+
68
+ # Obtengo el resto de la cadena
69
+ sql_string= sql_string[table_found.length..sql_string.length]
70
+ end
71
+
72
+ return tables
73
+
74
+
75
+ end
76
+
77
+ end
78
+
79
+ # Parsea s archivos recibidos
80
+ def parse_file(*files)
81
+
82
+ # Resultado
83
+ tables_string= []
84
+
85
+ files.each do |f|
86
+ sql_string= File.open(f).read
87
+ tables_string << sql_string
88
+ end
89
+
90
+ return parse_string(*tables_string)
91
+
92
+ end
93
+
94
+
95
+ private
96
+
97
+
98
+ def find_create_table sql_string
99
+ resultado = ''
100
+ numero_parentesis= 1
101
+
102
+ indexBajo= sql_string.index("(")+1
103
+ resultado= sql_string[0..indexBajo]
104
+
105
+ for n in indexBajo+1..sql_string.length-1 do
106
+ caracter = sql_string[n]
107
+ numero_parentesis= numero_parentesis+1 if caracter=="("
108
+ numero_parentesis= numero_parentesis-1 if caracter==")"
109
+ resultado = resultado+caracter
110
+ break if numero_parentesis==0
111
+ end
112
+
113
+ return resultado
114
+
115
+ end
116
+
117
+
118
+ def create_table create_table
119
+
120
+
121
+ #obtengo el nombre del campo
122
+ expresion_tabla= /CREATE\s+TABLE([^\(]+)/mi
123
+ expresion_tabla.match(create_table)
124
+ # Nombre en crudo
125
+ sql_name= $1
126
+ sql_name.strip!.gsub!("\"", '')
127
+
128
+ # Creo la tabla
129
+ tabla= EntitySchema.new :sql_name => sql_name
130
+
131
+ expresion_campo = /\[?(\S+?)\]?\s+\[?(int|n?varchar|n?char|money|real|int|smallint|datetime|bit)\]?\s*(IDENTITY)?\s*(?:\(([^\)]+?)\))?\s*(NOT\s+NULL|NULL)\s*/mi
132
+ expresion_contraint_primary= /CONSTRAINT\s+\S+\s+PRIMARY[^\(]+?\(([^\)]+)\)/mi
133
+
134
+
135
+ expresion_contraint_primary.match(create_table)
136
+ llaves_primarias= $1
137
+
138
+
139
+ #obtengo todos los campos
140
+ create_table.scan (expresion_campo) do |nombre, tipo, identity, longitud, nulo|
141
+
142
+ nombre.gsub!('([', '')
143
+
144
+ campo= EntityFieldSchema.new :sql_name => nombre, :sql_type => tipo
145
+
146
+ case tipo.upcase
147
+ when "VARCHAR", "CHAR", "NVARCHAR", "NCHAR"
148
+ campo.size= longitud if longitud
149
+ end
150
+
151
+ campo.allow_null = true if /NULL/i.match(nulo)
152
+ campo.allow_null = false if /NOT/i.match(nulo)
153
+
154
+ #reviso a ver si es llave primaria
155
+ campo.primary_key= true if llaves_primarias and llaves_primarias.index(campo.name)
156
+
157
+ #Agrega información de indentidad.
158
+ campo.identity = true if identity
159
+
160
+ #agrego el campo
161
+ tabla.fields.push campo
162
+ end
163
+
164
+
165
+ return tabla
166
+
167
+ end
168
+
169
+
170
+ end
171
+
172
+ end
@@ -0,0 +1,42 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ =begin
23
+ Este mixin se encarga de buscar tablas asociadas a entidades
24
+ =end
25
+
26
+
27
+ module CapicuaGen::Melchior
28
+
29
+ public
30
+ # Recupera las tablas asociadas a entidades
31
+ def get_tables
32
+ # Busco las caracteristicas que contiene entidades de SQL para una table
33
+ generator.get_features_in_targets_by_type(:entity_sql_table).each do |f|
34
+ # Obtengo las entidades
35
+ f.get_entities.each do |e|
36
+ yield e
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,32 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ =begin
23
+ Melchior es un conjunto de generadores de caracteristicas de ejemplo pertenecientes a CapicuaGen
24
+ que se ocupa entre otras cosas de definir las clase para manejar entidades.
25
+ =end
26
+
27
+ require_relative 'version'
28
+ require 'CapicuaGen/capicua_gen'
29
+ require_relative 'DataAccess/EntitySqlDataAccess/Source/entity_field_schema'
30
+ require_relative 'DataAccess/EntitySqlDataAccess/Source/entity_schema'
31
+ require_relative 'DataAccess/EntitySqlDataAccess/Source/entity_sql_data_access_feature'
32
+ require_relative 'DataAccess/EntitySqlDataAccess/Source/sql_table_parser'
@@ -0,0 +1,3 @@
1
+ module CapicuaGenMelchior
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: CapicuaGenMelchior
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - José Luis Bautista Martín
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: CapicuaGen
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.0.1
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.1
61
+ description: |
62
+ CapicuaGen
63
+
64
+ CapicuaGen es un software que ayuda a la creación automática de
65
+ sistemas empresariales a través de la definición y ensamblado de
66
+ diversos generadores de características.
67
+
68
+ Melchior es un conjunto de generadores de caracteristicas de ejemplo pertenecientes a CapicuaGen
69
+ que se ocupa entre otras cosas de definir las clase para manejar entidades.
70
+
71
+
72
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
73
+ del 2016.
74
+
75
+ Puede modificar y distribuir este software, según le plazca, y usarlo
76
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
77
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
78
+ código fuente.
79
+
80
+ Este software es código libre, y se licencia bajo LGPL.
81
+
82
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
83
+ email:
84
+ - joseluisbautista@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - CapicuaGenMelchior.gemspec
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/CapicuaGenMelchior/DataAccess/EntitySqlDataAccess/Source/entity_field_schema.rb
102
+ - lib/CapicuaGenMelchior/DataAccess/EntitySqlDataAccess/Source/entity_schema.rb
103
+ - lib/CapicuaGenMelchior/DataAccess/EntitySqlDataAccess/Source/entity_sql_data_access_feature.rb
104
+ - lib/CapicuaGenMelchior/DataAccess/EntitySqlDataAccess/Source/sql_table_parser.rb
105
+ - lib/CapicuaGenMelchior/Mixins/entity_sql_table_mixin.rb
106
+ - lib/CapicuaGenMelchior/melchior.rb
107
+ - lib/CapicuaGenMelchior/version.rb
108
+ homepage: http://desdelashorasextras.blogspot.mx/
109
+ licenses:
110
+ - LGPL
111
+ metadata:
112
+ allowed_push_host: https://rubygems.org
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.4.5.1
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: CapicuaGen es un software que ayuda a la creación automática de sistemas
133
+ empresariales a través de la definición y ensamblado de diversos generadores de
134
+ características. Melchior es un conjunto de generadores de caracteristicas de ejemplo
135
+ pertenecientes a CapicuaGen que se ocupa entre otras cosas de definir las clase
136
+ para manejar entidades. =end
137
+ test_files: []