tripper 0.0.3d
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/TODO +26 -0
- data/lib/generators/USAGE +8 -0
- data/lib/generators/tripper.rb +51 -0
- data/lib/generators/tripper/commonalities/commonalities.rb +226 -0
- data/lib/generators/tripper/detect_changes/detect_changes_generator.rb +173 -0
- data/lib/generators/tripper/detect_changes/model.rb +226 -0
- data/lib/generators/tripper/detect_changes/templates/migration.rb +7 -0
- data/lib/generators/tripper/detect_changes/templates/model/belongs_to.rb +1 -0
- data/lib/generators/tripper/detect_changes/templates/model/has_one.rb +1 -0
- data/lib/generators/tripper/detect_changes/templates/model/validates.rb +2 -0
- data/lib/generators/tripper/from_community/from_community_generator.rb +95 -0
- data/lib/generators/tripper/from_community/templates/actions/create.rb +8 -0
- data/lib/generators/tripper/from_community/templates/actions/destroy.rb +5 -0
- data/lib/generators/tripper/from_community/templates/actions/edit.rb +3 -0
- data/lib/generators/tripper/from_community/templates/actions/index.rb +3 -0
- data/lib/generators/tripper/from_community/templates/actions/new.rb +3 -0
- data/lib/generators/tripper/from_community/templates/actions/show.rb +3 -0
- data/lib/generators/tripper/from_community/templates/actions/update.rb +8 -0
- data/lib/generators/tripper/from_community/templates/controller.rb +3 -0
- data/lib/generators/tripper/from_community/templates/fixtures.yml +9 -0
- data/lib/generators/tripper/from_community/templates/helper.rb +2 -0
- data/lib/generators/tripper/from_community/templates/migration.rb +30 -0
- data/lib/generators/tripper/from_community/templates/model.rb +54 -0
- data/lib/generators/tripper/from_community/templates/tests/rspec/actions/create.rb +11 -0
- data/lib/generators/tripper/from_community/templates/tests/rspec/actions/destroy.rb +6 -0
- data/lib/generators/tripper/from_community/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/tripper/from_community/templates/tests/rspec/actions/index.rb +4 -0
- data/lib/generators/tripper/from_community/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/tripper/from_community/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/tripper/from_community/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/tripper/from_community/templates/tests/rspec/controller.rb +8 -0
- data/lib/generators/tripper/from_community/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/tripper/from_community/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/tripper/from_community/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/tripper/from_community/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/tripper/from_community/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/tripper/from_community/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/tripper/from_community/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/tripper/from_community/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/tripper/from_community/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/tripper/from_community/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/tripper/from_community/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/tripper/from_community/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/tripper/from_community/templates/views/erb/_form.html.erb +16 -0
- data/lib/generators/tripper/from_community/templates/views/erb/edit.html.erb +14 -0
- data/lib/generators/tripper/from_community/templates/views/erb/index.html.erb +29 -0
- data/lib/generators/tripper/from_community/templates/views/erb/new.html.erb +7 -0
- data/lib/generators/tripper/from_community/templates/views/erb/show.html.erb +25 -0
- data/lib/generators/tripper/from_community/templates/views/haml/_form.html.haml +9 -0
- data/lib/generators/tripper/from_community/templates/views/haml/edit.html.haml +14 -0
- data/lib/generators/tripper/from_community/templates/views/haml/index.html.haml +25 -0
- data/lib/generators/tripper/from_community/templates/views/haml/new.html.haml +7 -0
- data/lib/generators/tripper/from_community/templates/views/haml/show.html.haml +20 -0
- data/lib/generators/tripper/layout/USAGE +18 -0
- data/lib/generators/tripper/layout/layout_generator.rb +29 -0
- data/lib/generators/tripper/layout/templates/error_messages_helper.rb +23 -0
- data/lib/generators/tripper/layout/templates/layout.html.erb +19 -0
- data/lib/generators/tripper/layout/templates/layout.html.haml +21 -0
- data/lib/generators/tripper/layout/templates/layout_helper.rb +22 -0
- data/lib/generators/tripper/layout/templates/stylesheet.css +83 -0
- data/lib/generators/tripper/layout/templates/stylesheet.sass +73 -0
- data/lib/generators/tripper/obj_constraint.rb +23 -0
- data/lib/generators/tripper/predicate.rb +12 -0
- data/lib/generators/tripper/sync_with_community/model.rb +260 -0
- data/lib/generators/tripper/sync_with_community/sync_with_community_generator.rb +310 -0
- data/lib/generators/tripper/sync_with_community/templates/migration.rb +7 -0
- data/lib/generators/tripper/sync_with_community/templates/model/belongs_to.rb +1 -0
- data/lib/generators/tripper/sync_with_community/templates/model/has_one.rb +1 -0
- data/lib/generators/tripper/sync_with_community/templates/model/validates.rb +2 -0
- data/lib/generators/tripper/templates/actions/create.rb +8 -0
- data/lib/generators/tripper/templates/actions/destroy.rb +5 -0
- data/lib/generators/tripper/templates/actions/edit.rb +3 -0
- data/lib/generators/tripper/templates/actions/index.rb +3 -0
- data/lib/generators/tripper/templates/actions/new.rb +3 -0
- data/lib/generators/tripper/templates/actions/show.rb +3 -0
- data/lib/generators/tripper/templates/actions/update.rb +8 -0
- data/lib/generators/tripper/templates/controller.rb +3 -0
- data/lib/generators/tripper/templates/fixtures.yml +9 -0
- data/lib/generators/tripper/templates/helper.rb +2 -0
- data/lib/generators/tripper/templates/migration.rb +30 -0
- data/lib/generators/tripper/templates/model.rb +54 -0
- data/lib/generators/tripper/templates/tests/rspec/actions/create.rb +11 -0
- data/lib/generators/tripper/templates/tests/rspec/actions/destroy.rb +6 -0
- data/lib/generators/tripper/templates/tests/rspec/actions/edit.rb +4 -0
- data/lib/generators/tripper/templates/tests/rspec/actions/index.rb +4 -0
- data/lib/generators/tripper/templates/tests/rspec/actions/new.rb +4 -0
- data/lib/generators/tripper/templates/tests/rspec/actions/show.rb +4 -0
- data/lib/generators/tripper/templates/tests/rspec/actions/update.rb +11 -0
- data/lib/generators/tripper/templates/tests/rspec/controller.rb +8 -0
- data/lib/generators/tripper/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/tripper/templates/tests/shoulda/actions/create.rb +13 -0
- data/lib/generators/tripper/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/lib/generators/tripper/templates/tests/shoulda/actions/edit.rb +6 -0
- data/lib/generators/tripper/templates/tests/shoulda/actions/index.rb +6 -0
- data/lib/generators/tripper/templates/tests/shoulda/actions/new.rb +6 -0
- data/lib/generators/tripper/templates/tests/shoulda/actions/show.rb +6 -0
- data/lib/generators/tripper/templates/tests/shoulda/actions/update.rb +13 -0
- data/lib/generators/tripper/templates/tests/shoulda/controller.rb +5 -0
- data/lib/generators/tripper/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/tripper/templates/tests/testunit/actions/create.rb +11 -0
- data/lib/generators/tripper/templates/tests/testunit/actions/destroy.rb +6 -0
- data/lib/generators/tripper/templates/tests/testunit/actions/edit.rb +4 -0
- data/lib/generators/tripper/templates/tests/testunit/actions/index.rb +4 -0
- data/lib/generators/tripper/templates/tests/testunit/actions/new.rb +4 -0
- data/lib/generators/tripper/templates/tests/testunit/actions/show.rb +4 -0
- data/lib/generators/tripper/templates/tests/testunit/actions/update.rb +11 -0
- data/lib/generators/tripper/templates/tests/testunit/controller.rb +5 -0
- data/lib/generators/tripper/templates/tests/testunit/model.rb +7 -0
- data/lib/generators/tripper/templates/views/erb/_form.html.erb +16 -0
- data/lib/generators/tripper/templates/views/erb/edit.html.erb +14 -0
- data/lib/generators/tripper/templates/views/erb/index.html.erb +29 -0
- data/lib/generators/tripper/templates/views/erb/new.html.erb +7 -0
- data/lib/generators/tripper/templates/views/erb/show.html.erb +25 -0
- data/lib/generators/tripper/templates/views/haml/_form.html.haml +9 -0
- data/lib/generators/tripper/templates/views/haml/edit.html.haml +14 -0
- data/lib/generators/tripper/templates/views/haml/index.html.haml +25 -0
- data/lib/generators/tripper/templates/views/haml/new.html.haml +7 -0
- data/lib/generators/tripper/templates/views/haml/show.html.haml +20 -0
- data/lib/tripper.rb +1 -0
- data/lib/tripper/GOSPLDB/config/database.yml +6 -0
- data/lib/tripper/GOSPLDB/config_db.rb +9 -0
- data/lib/tripper/GOSPLDB/console +2 -0
- data/lib/tripper/GOSPLDB/gospl_db_classes.rb +343 -0
- data/lib/tripper/GOSPLDB/play_around.rb +4 -0
- data/lib/tripper/GOSPLDB/rakefile.rb +88 -0
- data/lib/tripper/GOSPLDBToORMDB/gospl_db_to_orm_db.rb +88 -0
- data/lib/tripper/ORMDB/config/database.yml +6 -0
- data/lib/tripper/ORMDB/config_db.rb +9 -0
- data/lib/tripper/ORMDB/console +2 -0
- data/lib/tripper/ORMDB/db/migrations/0_create_orm_object_table.rb +17 -0
- data/lib/tripper/ORMDB/db/migrations/10_create_no_lot_constraint_table.rb +17 -0
- data/lib/tripper/ORMDB/db/migrations/11_create_value_constraint_table.rb +14 -0
- data/lib/tripper/ORMDB/db/migrations/12_create_value_constraint_value_table.rb +16 -0
- data/lib/tripper/ORMDB/db/migrations/13_create_value_range_table.rb +15 -0
- data/lib/tripper/ORMDB/db/migrations/14_create_frequency_constraint_table.rb +16 -0
- data/lib/tripper/ORMDB/db/migrations/15_create_value_table.rb +15 -0
- data/lib/tripper/ORMDB/db/migrations/16_create_ring_constraint_table.rb +14 -0
- data/lib/tripper/ORMDB/db/migrations/17_create_orm_schema_table.rb +21 -0
- data/lib/tripper/ORMDB/db/migrations/18_create_uniqueness_constraint_table.rb +15 -0
- data/lib/tripper/ORMDB/db/migrations/1_create_no_lot_table.rb +18 -0
- data/lib/tripper/ORMDB/db/migrations/2_create_lot_table.rb +18 -0
- data/lib/tripper/ORMDB/db/migrations/3_create_object_role_table.rb +18 -0
- data/lib/tripper/ORMDB/db/migrations/4_create_reference_table.rb +17 -0
- data/lib/tripper/ORMDB/db/migrations/5_create_predicate_table.rb +18 -0
- data/lib/tripper/ORMDB/db/migrations/6_create_object_role_constraint_table.rb +18 -0
- data/lib/tripper/ORMDB/db/migrations/7_create_subtype_table.rb +17 -0
- data/lib/tripper/ORMDB/db/migrations/8_create_mandatory_constraint_table.rb +15 -0
- data/lib/tripper/ORMDB/db/migrations/9_create_constraint_table.rb +15 -0
- data/lib/tripper/ORMDB/db/orm_ml.sqlite3 +0 -0
- data/lib/tripper/ORMDB/db/orm_ml.sqlite3.backup +0 -0
- data/lib/tripper/ORMDB/db/orm_ml.sqlite3.juli28-2013 +0 -0
- data/lib/tripper/ORMDB/db/orm_ml.sqlite3.old +0 -0
- data/lib/tripper/ORMDB/db/schema.rb +58 -0
- data/lib/tripper/ORMDB/erd.pdf +0 -0
- data/lib/tripper/ORMDB/migrate_db.rb +21 -0
- data/lib/tripper/ORMDB/orm_db_classes.rb +423 -0
- data/lib/tripper/ORMDB/populate.rb +4 -0
- data/lib/tripper/ORMDB/rakefile.rb +88 -0
- data/lib/tripper/model_parsers/attribute_parser/AttributeParser.g +50 -0
- data/lib/tripper/model_parsers/attribute_parser/AttributeParser.tokens +13 -0
- data/lib/tripper/model_parsers/attribute_parser/AttributeParserLexer.rb +538 -0
- data/lib/tripper/model_parsers/attribute_parser/AttributeParserParser.rb +412 -0
- data/lib/tripper/model_parsers/attribute_parser/playing_around.rb +14 -0
- data/lib/tripper/model_parsers/belongs_to/BelongsToParser.g +63 -0
- data/lib/tripper/model_parsers/belongs_to/BelongsToParser.tokens +21 -0
- data/lib/tripper/model_parsers/belongs_to/BelongsToParserLexer.rb +667 -0
- data/lib/tripper/model_parsers/belongs_to/BelongsToParserParser.rb +552 -0
- data/lib/tripper/model_parsers/belongs_to/playing_around.rb +9 -0
- data/lib/tripper/model_parsers/database_fields_parser/DatabaseFieldsParser.g +47 -0
- data/lib/tripper/model_parsers/database_fields_parser/DatabaseFieldsParser.tokens +14 -0
- data/lib/tripper/model_parsers/database_fields_parser/DatabaseFieldsParserLexer.rb +513 -0
- data/lib/tripper/model_parsers/database_fields_parser/DatabaseFieldsParserParser.rb +279 -0
- data/lib/tripper/model_parsers/database_fields_parser/playing_around.rb +14 -0
- data/lib/tripper/model_parsers/has_and_belongs_to_many/HasAndBelongsToManyParser.g +92 -0
- data/lib/tripper/model_parsers/has_and_belongs_to_many/HasAndBelongsToManyParser.tokens +25 -0
- data/lib/tripper/model_parsers/has_and_belongs_to_many/HasAndBelongsToManyParserLexer.rb +787 -0
- data/lib/tripper/model_parsers/has_and_belongs_to_many/HasAndBelongsToManyParserParser.rb +1024 -0
- data/lib/tripper/model_parsers/has_and_belongs_to_many/playing_around.rb +9 -0
- data/lib/tripper/model_parsers/has_many/HasManyParser.g +77 -0
- data/lib/tripper/model_parsers/has_many/HasManyParser.tokens +23 -0
- data/lib/tripper/model_parsers/has_many/HasManyParserLexer.rb +710 -0
- data/lib/tripper/model_parsers/has_many/HasManyParserParser.rb +788 -0
- data/lib/tripper/model_parsers/has_many/playing_around.rb +9 -0
- data/lib/tripper/model_parsers/has_one/HasOneParser.g +63 -0
- data/lib/tripper/model_parsers/has_one/HasOneParser.tokens +21 -0
- data/lib/tripper/model_parsers/has_one/HasOneParserLexer.rb +664 -0
- data/lib/tripper/model_parsers/has_one/HasOneParserParser.rb +552 -0
- data/lib/tripper/model_parsers/has_one/playing_around.rb +9 -0
- data/lib/tripper/model_parsers/validates/ValidatesParser.g +68 -0
- data/lib/tripper/model_parsers/validates/ValidatesParser.tokens +35 -0
- data/lib/tripper/model_parsers/validates/ValidatesParserLexer.rb +899 -0
- data/lib/tripper/model_parsers/validates/ValidatesParserParser.rb +869 -0
- data/lib/tripper/model_parsers/validates/playing_around.rb +9 -0
- data/lib/tripper/rails.rb +8 -0
- data/lib/tripper/version.rb +3 -0
- data/tripper.gemspec +33 -0
- metadata +408 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7339a2d3e63498c66edf203ea23d3b1a8f782ae8
|
4
|
+
data.tar.gz: ad0d3b114dcd60dbd9d1baff787461ac3ebf2459
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 376aac902ab5bd5a675a9ca89de086d4c95f33c4f52fb696f8a56759704ba61a8e9ca4a4b11c4c2bea033b89a2958ba193fb6025090d77b9ac9eca2d1cfe194b
|
7
|
+
data.tar.gz: 6b1efc9fc2e8557e5aa7457aaa0a50887a6486ebbaaf1a3abe0e3b940feaaafd5c3de4fa0a140ffa6f9b50fd72c8a854c3588b1fe431dc2410bc64706882fb8a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Rik Vanmechelen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Tripper
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tripper'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tripper
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/TODO
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
- Ontology change request tracking
|
2
|
+
- Create corresponding post in GOSPL
|
3
|
+
/ Ontology change detection
|
4
|
+
- Code generation from ontology change
|
5
|
+
- set constraints from ORMML
|
6
|
+
- generate from ORMML
|
7
|
+
|
8
|
+
|
9
|
+
- check the uniqueness constraints again! check the psuedocode for the correct answer!
|
10
|
+
|
11
|
+
______
|
12
|
+
|------------|
|
13
|
+
Department ---- | | | ----- Person
|
14
|
+
|------------|
|
15
|
+
d1 | p1 => ok
|
16
|
+
d1 | p2 => ok
|
17
|
+
d2 | p3 => ok
|
18
|
+
d2 | p1 => NOT ok
|
19
|
+
=> Person needs a belongs_to dep, and that is ALL, ok trust me i tried it out...
|
20
|
+
|
21
|
+
Also presence has to be checked again...
|
22
|
+
|
23
|
+
|------------|
|
24
|
+
Customer ---- | | | O---- Transaction
|
25
|
+
|------------|
|
26
|
+
=> put validate_presence_of :customer in transaction
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'tripper/GOSPLDB/gospl_db_classes'
|
3
|
+
require 'tripper/ORMDB/orm_db_classes'
|
4
|
+
|
5
|
+
module Tripper
|
6
|
+
module Generators
|
7
|
+
class Base < Rails::Generators::Base
|
8
|
+
#desc "Tripper generators"
|
9
|
+
|
10
|
+
# Commandline options can be defined here using Thor-like options:
|
11
|
+
#class_option :com_name, :type => :string
|
12
|
+
|
13
|
+
# I can later access that option using:
|
14
|
+
# options[:my_opt]
|
15
|
+
|
16
|
+
|
17
|
+
def self.source_root
|
18
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'tripper', 'templates'))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.banner
|
22
|
+
"rails generate tripper:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Generator Code. Remember this is just suped-up Thor so methods are executed in order
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def add_gem(name, options = {})
|
30
|
+
gemfile_content = File.read(destination_path("Gemfile"))
|
31
|
+
File.open(destination_path("Gemfile"), 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
|
32
|
+
gem name, options unless gemfile_content.include? name
|
33
|
+
end
|
34
|
+
|
35
|
+
def print_usage
|
36
|
+
self.class.help(Thor::Base.shell.new)
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
|
40
|
+
def generating?
|
41
|
+
:invoke == behavior
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroying?
|
45
|
+
:revoke == behavior
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'generators/tripper'
|
2
|
+
require 'generators/tripper/obj_constraint'
|
3
|
+
require 'generators/tripper/predicate'
|
4
|
+
|
5
|
+
require 'rails/generators'
|
6
|
+
require 'rails/generators/migration'
|
7
|
+
require 'rails/generators/generated_attribute'
|
8
|
+
require 'tripper/GOSPLDB/gospl_db_classes'
|
9
|
+
require 'tripper/ORMDB/orm_db_classes'
|
10
|
+
require 'tripper/GOSPLDBToORMDB/gospl_db_to_orm_db'
|
11
|
+
|
12
|
+
module Tripper
|
13
|
+
module Generators
|
14
|
+
module Commonalities
|
15
|
+
@@controller_actions = %w[index show new create edit update destroy]
|
16
|
+
|
17
|
+
def create_new_ontology_models schema_label
|
18
|
+
community = Tripper::ORMDB::OrmSchema.find_by_title schema_label
|
19
|
+
if community
|
20
|
+
community.no_lots.each do |nolot|
|
21
|
+
@nolot = nolot
|
22
|
+
@name = nolot.name
|
23
|
+
#also check for inheritance of ActiveRecord::Base, because some words are already ruby classes (e.g. Time)
|
24
|
+
@class_name = get_class_name @nolot
|
25
|
+
@model_attributes = []
|
26
|
+
@nolot.identifying_constraint_objects.lots.each do |lot|
|
27
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(lot_attribute_name(lot), "String")
|
28
|
+
end
|
29
|
+
create_ontology_model
|
30
|
+
end
|
31
|
+
puts community.inspect
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def action?(name)
|
36
|
+
@@controller_actions.include? name.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
def actions?(*names)
|
40
|
+
names.all? { |name| action? name }
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_class
|
44
|
+
Kernel.const_get(@name)
|
45
|
+
end
|
46
|
+
|
47
|
+
def lot_attribute_name lot
|
48
|
+
unless lot.application_name
|
49
|
+
lot.application_name = attribute_nameify lot.name
|
50
|
+
lot.save
|
51
|
+
end
|
52
|
+
lot.application_name
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_class_name nolot
|
56
|
+
unless nolot.application_name
|
57
|
+
nolot.application_name = check_for_class_name nolot.name
|
58
|
+
nolot.save
|
59
|
+
end
|
60
|
+
nolot.application_name
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_ontology_name label
|
64
|
+
new_label = label
|
65
|
+
while new_label[0,2] == "My"
|
66
|
+
new_label = new_label[2..-1]
|
67
|
+
end
|
68
|
+
new_label
|
69
|
+
end
|
70
|
+
|
71
|
+
def remove_id label
|
72
|
+
new_label = label
|
73
|
+
while new_label[-3..-1] == "_id"
|
74
|
+
new_label = new_label[0..-4]
|
75
|
+
end
|
76
|
+
new_label
|
77
|
+
end
|
78
|
+
|
79
|
+
def create_class_name
|
80
|
+
check_for_class_name @name
|
81
|
+
end
|
82
|
+
|
83
|
+
def check_for_class_name name
|
84
|
+
(class_exists?(name) && !(Kernel.const_get(name) < ActiveRecord::Base)) ? ("My"+name).camelize : name.camelize
|
85
|
+
end
|
86
|
+
|
87
|
+
def plural_name
|
88
|
+
@class_name.underscore.pluralize
|
89
|
+
end
|
90
|
+
|
91
|
+
def plural_class_name
|
92
|
+
plural_name.camelize
|
93
|
+
end
|
94
|
+
|
95
|
+
def model_path
|
96
|
+
@class_name.underscore
|
97
|
+
end
|
98
|
+
|
99
|
+
def singular_name
|
100
|
+
@class_name.underscore
|
101
|
+
end
|
102
|
+
|
103
|
+
def attribute_nameify name
|
104
|
+
name.underscore.tr(" ", "_") #the last one is to remove spaces
|
105
|
+
end
|
106
|
+
|
107
|
+
def attribute_is_foreign_key? label
|
108
|
+
label[-3..-1] == "_id"
|
109
|
+
end
|
110
|
+
|
111
|
+
def items_path
|
112
|
+
if action? :index
|
113
|
+
"#{item_resource.pluralize}_path"
|
114
|
+
else
|
115
|
+
"root_path"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def form_partial?
|
120
|
+
actions? :new, :edit
|
121
|
+
end
|
122
|
+
|
123
|
+
def render_form
|
124
|
+
if form_partial?
|
125
|
+
if options.haml?
|
126
|
+
"= render \"form\""
|
127
|
+
else
|
128
|
+
"<%= render \"form\" %>"
|
129
|
+
end
|
130
|
+
else
|
131
|
+
read_template("views/#{view_language}/_form.html.#{view_language}")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def view_language
|
136
|
+
options.haml? ? 'haml' : 'erb'
|
137
|
+
end
|
138
|
+
|
139
|
+
def controller_methods(dir_name)
|
140
|
+
@@controller_actions.map do |action|
|
141
|
+
read_template("#{dir_name}/#{action}.rb")
|
142
|
+
end.join("\n").strip
|
143
|
+
end
|
144
|
+
|
145
|
+
def read_template(relative_path)
|
146
|
+
ERB.new(File.read(find_in_source_paths(relative_path)), nil, '-').result(binding)
|
147
|
+
end
|
148
|
+
|
149
|
+
def instances_name
|
150
|
+
instance_name.pluralize
|
151
|
+
end
|
152
|
+
|
153
|
+
def instance_name
|
154
|
+
@class_name.split('/').last.underscore
|
155
|
+
end
|
156
|
+
|
157
|
+
def item_path(options = {})
|
158
|
+
name = options[:instance_variable] ? "@#{instance_name}" : instance_name
|
159
|
+
suffix = options[:full_url] ? "url" : "path"
|
160
|
+
if options[:action].to_s == "new"
|
161
|
+
"new_#{item_resource}_#{suffix}"
|
162
|
+
elsif options[:action].to_s == "edit"
|
163
|
+
"edit_#{item_resource}_#{suffix}(#{name})"
|
164
|
+
else
|
165
|
+
if @class_name.include?('::') && !@namespace_model
|
166
|
+
namespace = singular_name.split('/')[0..-2]
|
167
|
+
"[:#{namespace.join(', :')}, #{name}]"
|
168
|
+
else
|
169
|
+
name
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def item_resource
|
175
|
+
@class_name.underscore.gsub('/','_')
|
176
|
+
end
|
177
|
+
|
178
|
+
def item_url
|
179
|
+
if action? :show
|
180
|
+
item_path(:full_url => true, :instance_variable => true)
|
181
|
+
else
|
182
|
+
items_url
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def items_url
|
187
|
+
if action? :index
|
188
|
+
item_resource.pluralize + '_url'
|
189
|
+
else
|
190
|
+
"root_url"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def create_model
|
195
|
+
template 'model.rb', "app/models/#{model_path}.rb"
|
196
|
+
template 'model.rb', "app/tripper/models/#{model_path}.rb"
|
197
|
+
end
|
198
|
+
|
199
|
+
def create_ontology_model
|
200
|
+
template 'model.rb', "app/tripper/ontology_models/#{model_path}.rb"
|
201
|
+
end
|
202
|
+
|
203
|
+
def create_migration
|
204
|
+
migration_template 'migration.rb', "db/migrate/create_#{model_path.pluralize.gsub('/', '_')}.rb"
|
205
|
+
end
|
206
|
+
|
207
|
+
def create_controller
|
208
|
+
template 'controller.rb', "app/controllers/#{plural_name}_controller.rb"
|
209
|
+
|
210
|
+
template 'helper.rb', "app/helpers/#{plural_name}_helper.rb"
|
211
|
+
|
212
|
+
%w[index show new edit].each do |action|
|
213
|
+
template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
|
214
|
+
end
|
215
|
+
|
216
|
+
template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
|
217
|
+
|
218
|
+
namespaces = plural_name.split('/')
|
219
|
+
resource = namespaces.pop
|
220
|
+
route namespaces.reverse.inject("resources :#{resource}") { |acc, namespace|
|
221
|
+
"namespace(:#{namespace}){ #{acc} }"
|
222
|
+
}
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'generators/tripper'
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'rails/generators/migration'
|
5
|
+
require 'rails/generators/generated_attribute'
|
6
|
+
|
7
|
+
require 'tripper/GOSPLDB/gospl_db_classes'
|
8
|
+
require 'tripper/ORMDB/orm_db_classes'
|
9
|
+
require 'generators/tripper/detect_changes/model'
|
10
|
+
|
11
|
+
module Tripper
|
12
|
+
module Generators
|
13
|
+
class DetectChangesGenerator < Base
|
14
|
+
include Rails::Generators::Migration
|
15
|
+
|
16
|
+
attr_accessor :models, :tripper_models
|
17
|
+
|
18
|
+
desc "Detect changes to the model code"
|
19
|
+
|
20
|
+
argument :community_name, :type => :string
|
21
|
+
|
22
|
+
#class varialbe for timestamps
|
23
|
+
@@timestamp = Time.now.utc
|
24
|
+
|
25
|
+
def initialize (*args, &block)
|
26
|
+
super
|
27
|
+
@models = []
|
28
|
+
@models = Dir.glob("app/models/*.rb").inject([]) {|res, path| res << Model.new(path); res}
|
29
|
+
@tripper_models = Dir.glob("app/tripper/models/*.rb").inject([]) {|res, path| res << Model.new(path); res}
|
30
|
+
# @models.each_index { |i| puts "#{@models[i].class_name}: #{@models[i] == @tripper_models[i]} :#{@tripper_models[i].class_name}"
|
31
|
+
# }
|
32
|
+
puts "There are no changes" unless find_differences
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def find_differences
|
38
|
+
pending_changes = false
|
39
|
+
detect_lexon_duplicates = Set.new
|
40
|
+
@tripper_models.each do |tripper_model|
|
41
|
+
app_model = @models.find {|m| m.class_name == tripper_model.class_name}
|
42
|
+
unless app_model == tripper_model
|
43
|
+
pending_changes = true
|
44
|
+
differences = app_model.differences tripper_model
|
45
|
+
puts differences.inspect
|
46
|
+
model_changes = get_model_changes differences
|
47
|
+
ontology_changes = get_ontology_changes differences, detect_lexon_duplicates
|
48
|
+
puts model_changes
|
49
|
+
write_changes_to_file app_model, model_changes
|
50
|
+
get_migration_changes differences
|
51
|
+
end
|
52
|
+
end
|
53
|
+
return pending_changes
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_migration_changes differences
|
57
|
+
unless differences.attributes_diff.lacking.empty?
|
58
|
+
@migration_action = "add" # remove is the oposite :)
|
59
|
+
@migration_name = differences.model1.class_name.pluralize
|
60
|
+
@diff_string_list = differences.attributes_diff.lacking.map(&:camelize).join("And")
|
61
|
+
@differences = differences
|
62
|
+
migration_template 'migration.rb', "db/migrate/#{@migration_action}_#{@diff_string_list.underscore}_to_#{@migration_name.underscore}.rb"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_model_changes differences
|
67
|
+
changes = []
|
68
|
+
unless differences.belongs_tos_diff.lacking.empty?
|
69
|
+
differences.belongs_tos_diff.lacking.each do |belongs_to_obj|
|
70
|
+
changes << create_belongs_to(belongs_to_obj)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
unless differences.has_ones_diff.lacking.empty?
|
74
|
+
differences.has_ones_diff.lacking.each do |has_one_obj|
|
75
|
+
changes << create_has_one(has_one_obj)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
unless differences.validations_diff.lacking.empty?
|
79
|
+
differences.validations_diff.lacking.each do |validation_obj|
|
80
|
+
changes << create_validation(validation_obj)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
return changes
|
84
|
+
end
|
85
|
+
|
86
|
+
def general_ontoloty_diference_detection differences, dups, method
|
87
|
+
differences.send(method).extra.each do |belongs_to_obj|
|
88
|
+
head = differences.model1.class_name.camelize.singularize
|
89
|
+
tail = belongs_to_obj.name.camelize.singularize
|
90
|
+
role = "has"
|
91
|
+
corole = "of"
|
92
|
+
unless dups.include? (head+role+corole+tail)
|
93
|
+
dups << (head+role+corole+tail)
|
94
|
+
dups << (tail+role+corole+head)
|
95
|
+
puts "new lexon: head=#{head} role=#{role} corole=#{corole} tail=#{tail}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_ontology_changes differences, dups
|
101
|
+
changes = []
|
102
|
+
unless differences.belongs_tos_diff.extra.empty?
|
103
|
+
general_ontoloty_diference_detection differences, dups, :belongs_tos_diff
|
104
|
+
end
|
105
|
+
unless differences.has_ones_diff.extra.empty?
|
106
|
+
general_ontoloty_diference_detection differences, dups, :has_ones_diff
|
107
|
+
end
|
108
|
+
unless differences.has_manies_diff.extra.empty?
|
109
|
+
general_ontoloty_diference_detection differences, dups, :has_manies_diff
|
110
|
+
end
|
111
|
+
unless differences.has_and_belongs_to_manies_diff.extra.empty?
|
112
|
+
general_ontoloty_diference_detection differences, dups, :has_and_belongs_to_manies_diff
|
113
|
+
end
|
114
|
+
unless differences.validations_diff.extra.empty?
|
115
|
+
differences.validations_diff.extra.each do |validation_obj|
|
116
|
+
"new validation"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
return changes
|
120
|
+
end
|
121
|
+
|
122
|
+
def write_changes_to_file app_model, changes
|
123
|
+
lines = IO.readlines(app_model.path).map do |line|
|
124
|
+
if line.include?("class") && line.include?(app_model.class_name)
|
125
|
+
line = line + '' + changes.join('')
|
126
|
+
end
|
127
|
+
line
|
128
|
+
end
|
129
|
+
File.open(app_model.path, 'w') do |file|
|
130
|
+
file.puts lines
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def create_belongs_to obj
|
135
|
+
@belongs_to_obj = obj
|
136
|
+
read_template("model/belongs_to.rb")
|
137
|
+
end
|
138
|
+
|
139
|
+
def create_has_one obj
|
140
|
+
@has_one_obj = obj
|
141
|
+
read_template("model/has_one.rb")
|
142
|
+
end
|
143
|
+
|
144
|
+
def create_validation obj
|
145
|
+
@validation = obj
|
146
|
+
read_template("model/validates.rb")
|
147
|
+
end
|
148
|
+
|
149
|
+
def create_validation_scope scope
|
150
|
+
if scope.empty?
|
151
|
+
return "true"
|
152
|
+
elsif scope.size == 1
|
153
|
+
return "{:scope => :#{scope.first}}"
|
154
|
+
else
|
155
|
+
return "{:scope => [#{scope.map{|s| ':'+s}.join(", ")}]}"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def read_template(relative_path)
|
160
|
+
ERB.new(File.read(find_in_source_paths(relative_path)), nil, '-').result(binding)
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.next_migration_number(dirname) #:nodoc:
|
164
|
+
if ActiveRecord::Base.timestamped_migrations
|
165
|
+
@@timestamp = @@timestamp + 1.seconds
|
166
|
+
@@timestamp.strftime("%Y%m%d%H%M%S")
|
167
|
+
else
|
168
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|