engine-rea 0.1.0

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.
Files changed (87) hide show
  1. data/.watchr +55 -0
  2. data/Gemfile +29 -0
  3. data/Gemfile.lock +165 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +4 -0
  6. data/Rakefile +48 -0
  7. data/VERSION +1 -0
  8. data/app/assets/images/rea/.gitkeep +0 -0
  9. data/app/assets/javascripts/rea/application.js +15 -0
  10. data/app/assets/stylesheets/rea/application.css +13 -0
  11. data/app/controllers/rea/application_controller.rb +4 -0
  12. data/app/helpers/rea/application_helper.rb +4 -0
  13. data/app/models/rea/category.rb +8 -0
  14. data/app/models/rea/category_member.rb +7 -0
  15. data/app/models/rea/category_type.rb +7 -0
  16. data/app/models/rea/group.rb +11 -0
  17. data/app/models/rea/group_entity.rb +7 -0
  18. data/app/models/rea/identifier.rb +42 -0
  19. data/app/views/layouts/rea/application.html.erb +14 -0
  20. data/config/routes.rb +2 -0
  21. data/db/migrate/20120601074531_create_rea_category_types.rb +13 -0
  22. data/db/migrate/20120601074540_create_rea_categories.rb +12 -0
  23. data/db/migrate/20120605023205_create_rea_category_members.rb +12 -0
  24. data/db/migrate/20120605030658_create_rea_groups.rb +9 -0
  25. data/db/migrate/20120605030708_create_rea_group_entities.rb +9 -0
  26. data/db/migrate/20120605082028_create_rea_identifiers.rb +11 -0
  27. data/lib/generators/rea/install/USAGE +8 -0
  28. data/lib/generators/rea/install/install_generator.rb +20 -0
  29. data/lib/rea/dsl/behavioral.rb +40 -0
  30. data/lib/rea/dsl/structural.rb +70 -0
  31. data/lib/rea/dsl.rb +20 -0
  32. data/lib/rea/engine.rb +11 -0
  33. data/lib/rea.rb +7 -0
  34. data/lib/tasks/cucumber.rake +65 -0
  35. data/lib/tasks/rea_tasks.rake +4 -0
  36. data/lib/tasks/watchr.rake +4 -0
  37. data/rea.gemspec +169 -0
  38. data/script/cucumber +10 -0
  39. data/script/rails +8 -0
  40. data/spec/dummy/README.rdoc +261 -0
  41. data/spec/dummy/Rakefile +7 -0
  42. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  43. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  44. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  46. data/spec/dummy/app/mailers/.gitkeep +0 -0
  47. data/spec/dummy/app/models/.gitkeep +0 -0
  48. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  49. data/spec/dummy/config/application.rb +61 -0
  50. data/spec/dummy/config/boot.rb +10 -0
  51. data/spec/dummy/config/database.yml +25 -0
  52. data/spec/dummy/config/environment.rb +5 -0
  53. data/spec/dummy/config/environments/development.rb +37 -0
  54. data/spec/dummy/config/environments/production.rb +67 -0
  55. data/spec/dummy/config/environments/test.rb +37 -0
  56. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/spec/dummy/config/initializers/inflections.rb +15 -0
  58. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  59. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  60. data/spec/dummy/config/initializers/session_store.rb +8 -0
  61. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  62. data/spec/dummy/config/locales/en.yml +5 -0
  63. data/spec/dummy/config/routes.rb +4 -0
  64. data/spec/dummy/config.ru +4 -0
  65. data/spec/dummy/db/development.sqlite3 +0 -0
  66. data/spec/dummy/db/schema.rb +71 -0
  67. data/spec/dummy/lib/assets/.gitkeep +0 -0
  68. data/spec/dummy/log/.gitkeep +0 -0
  69. data/spec/dummy/public/404.html +26 -0
  70. data/spec/dummy/public/422.html +26 -0
  71. data/spec/dummy/public/500.html +25 -0
  72. data/spec/dummy/public/favicon.ico +0 -0
  73. data/spec/dummy/script/rails +6 -0
  74. data/spec/factories/rea_resources.rb +6 -0
  75. data/spec/generators/rea/install/install_generator_spec.rb +27 -0
  76. data/spec/models/rea/category_member_spec.rb +5 -0
  77. data/spec/models/rea/category_spec.rb +5 -0
  78. data/spec/models/rea/category_type_spec.rb +5 -0
  79. data/spec/models/rea/group_entity_spec.rb +5 -0
  80. data/spec/models/rea/group_spec.rb +5 -0
  81. data/spec/models/rea/identifier_spec.rb +48 -0
  82. data/spec/rea/dsl/behavioral_spec.rb +81 -0
  83. data/spec/rea/dsl/structural_spec.rb +141 -0
  84. data/spec/rea/dsl_spec.rb +11 -0
  85. data/spec/rea/engine_spec.rb +10 -0
  86. data/spec/spec_helper.rb +35 -0
  87. metadata +391 -0
data/.watchr ADDED
@@ -0,0 +1,55 @@
1
+ def run(cmd)
2
+ puts(cmd)
3
+ `#{cmd}`
4
+ end
5
+
6
+ def growl(first, result)
7
+ passed = result.include?(' 0 failures')
8
+ title = "RSpec Test #{ passed ? "Successful!" : "Failed..."}"
9
+ image = passed ? "info" : "error"
10
+ severity = passed ? "low" : "critical"
11
+ body = result[/(Finished.+\n.+)+/]
12
+ options = "-i #{image} -u #{severity} '#{title}' '#{body}'"
13
+ system "notify-send #{options} &"
14
+ end
15
+
16
+ def run_spec(file)
17
+ unless File.exist?(file)
18
+ puts "#{file} does not exist"
19
+ return
20
+ end
21
+
22
+ puts "Running #{file}"
23
+ result = run("bundle exec rspec #{file}")
24
+ growl(result.split("\n").first, result) rescue nil
25
+ puts result
26
+ end
27
+
28
+ watch("lib/(.*/.*)\.rb") do |match|
29
+ run_spec %{spec/#{match[1]}_spec.rb}
30
+ end
31
+
32
+ watch("lib/(.*/.*/.*)\.rb") do |match|
33
+ run_spec %{spec/#{match[1]}_spec.rb}
34
+ end
35
+
36
+ watch("lib/(.*/.*/.*/.*)\.rb") do |match|
37
+ run_spec %{spec/#{match[1]}_spec.rb}
38
+ end
39
+
40
+ watch("app/(.*/.*)\.rb") do |match|
41
+ run_spec %{spec/#{match[1]}_spec.rb}
42
+ end
43
+
44
+ watch("spec/.*/*_spec\.rb") do |match|
45
+ run_spec match[0]
46
+ end
47
+
48
+ watch("spec/.*/.*/*_spec\.rb") do |match|
49
+ run_spec match[0]
50
+ end
51
+
52
+ watch("spec/.*/.*/.*/*_spec\.rb") do |match|
53
+ run_spec match[0]
54
+ end
55
+
data/Gemfile ADDED
@@ -0,0 +1,29 @@
1
+ source "http://ruby.taobao.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "rails", ">=3.2.0"
7
+ gem "capybara", ">= 0.4.0"
8
+
9
+ group :development,:test do
10
+ gem "database_cleaner"
11
+ gem "sqlite3"
12
+ gem 'factory_girl_rails'
13
+ gem 'minitest'
14
+ gem "rspec-rails", ">= 2.8.0"
15
+ gem "sqlite3-ruby"
16
+ gem "with_model", '>= 0.1.5'
17
+ gem "generator_spec"
18
+ gem "rdoc", "~> 3.12"
19
+ gem "bundler", ">= 1.0.0"
20
+ gem "jeweler", ">= 1.8.3"
21
+ gem "simplecov", ">= 0"
22
+ gem 'spork', '~> 1.0rc'
23
+ gem 'watchr'
24
+ end
25
+
26
+
27
+ # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
28
+ # gem 'ruby-debug'
29
+ # gem 'ruby-debug19'
data/Gemfile.lock ADDED
@@ -0,0 +1,165 @@
1
+ GEM
2
+ remote: http://ruby.taobao.org/
3
+ specs:
4
+ actionmailer (3.2.3)
5
+ actionpack (= 3.2.3)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.3)
8
+ activemodel (= 3.2.3)
9
+ activesupport (= 3.2.3)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.1)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.2)
17
+ activemodel (3.2.3)
18
+ activesupport (= 3.2.3)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.3)
21
+ activemodel (= 3.2.3)
22
+ activesupport (= 3.2.3)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.3)
26
+ activemodel (= 3.2.3)
27
+ activesupport (= 3.2.3)
28
+ activesupport (3.2.3)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ addressable (2.2.8)
32
+ arel (3.0.2)
33
+ builder (3.0.0)
34
+ capybara (1.1.2)
35
+ mime-types (>= 1.16)
36
+ nokogiri (>= 1.3.3)
37
+ rack (>= 1.0.0)
38
+ rack-test (>= 0.5.4)
39
+ selenium-webdriver (~> 2.0)
40
+ xpath (~> 0.1.4)
41
+ childprocess (0.3.2)
42
+ ffi (~> 1.0.6)
43
+ database_cleaner (0.7.2)
44
+ diff-lcs (1.1.3)
45
+ erubis (2.7.0)
46
+ factory_girl (3.3.0)
47
+ activesupport (>= 3.0.0)
48
+ factory_girl_rails (3.3.0)
49
+ factory_girl (~> 3.3.0)
50
+ railties (>= 3.0.0)
51
+ ffi (1.0.11)
52
+ generator_spec (0.8.5)
53
+ rails (>= 3.0, < 4.0)
54
+ rspec-rails
55
+ git (1.2.5)
56
+ hike (1.2.1)
57
+ i18n (0.6.0)
58
+ jeweler (1.8.3)
59
+ bundler (~> 1.0)
60
+ git (>= 1.2.5)
61
+ rake
62
+ rdoc
63
+ journey (1.0.3)
64
+ json (1.7.3)
65
+ libwebsocket (0.1.3)
66
+ addressable
67
+ mail (2.4.4)
68
+ i18n (>= 0.4.0)
69
+ mime-types (~> 1.16)
70
+ treetop (~> 1.4.8)
71
+ mime-types (1.18)
72
+ minitest (3.0.0)
73
+ multi_json (1.3.6)
74
+ nokogiri (1.5.2)
75
+ polyglot (0.3.3)
76
+ rack (1.4.1)
77
+ rack-cache (1.2)
78
+ rack (>= 0.4)
79
+ rack-ssl (1.3.2)
80
+ rack
81
+ rack-test (0.6.1)
82
+ rack (>= 1.0)
83
+ rails (3.2.3)
84
+ actionmailer (= 3.2.3)
85
+ actionpack (= 3.2.3)
86
+ activerecord (= 3.2.3)
87
+ activeresource (= 3.2.3)
88
+ activesupport (= 3.2.3)
89
+ bundler (~> 1.0)
90
+ railties (= 3.2.3)
91
+ railties (3.2.3)
92
+ actionpack (= 3.2.3)
93
+ activesupport (= 3.2.3)
94
+ rack-ssl (~> 1.3.2)
95
+ rake (>= 0.8.7)
96
+ rdoc (~> 3.4)
97
+ thor (~> 0.14.6)
98
+ rake (0.9.2.2)
99
+ rdoc (3.12)
100
+ json (~> 1.4)
101
+ rspec (2.10.0)
102
+ rspec-core (~> 2.10.0)
103
+ rspec-expectations (~> 2.10.0)
104
+ rspec-mocks (~> 2.10.0)
105
+ rspec-core (2.10.1)
106
+ rspec-expectations (2.10.0)
107
+ diff-lcs (~> 1.1.3)
108
+ rspec-mocks (2.10.1)
109
+ rspec-rails (2.10.1)
110
+ actionpack (>= 3.0)
111
+ activesupport (>= 3.0)
112
+ railties (>= 3.0)
113
+ rspec (~> 2.10.0)
114
+ rubyzip (0.9.8)
115
+ selenium-webdriver (2.21.2)
116
+ childprocess (>= 0.2.5)
117
+ ffi (~> 1.0)
118
+ libwebsocket (~> 0.1.3)
119
+ multi_json (~> 1.0)
120
+ rubyzip
121
+ simplecov (0.6.2)
122
+ multi_json (~> 1.3)
123
+ simplecov-html (~> 0.5.3)
124
+ simplecov-html (0.5.3)
125
+ spork (1.0.0rc3)
126
+ sprockets (2.1.3)
127
+ hike (~> 1.2)
128
+ rack (~> 1.0)
129
+ tilt (~> 1.1, != 1.3.0)
130
+ sqlite3 (1.3.6)
131
+ sqlite3-ruby (1.3.3)
132
+ sqlite3 (>= 1.3.3)
133
+ thor (0.14.6)
134
+ tilt (1.3.3)
135
+ treetop (1.4.10)
136
+ polyglot
137
+ polyglot (>= 0.3.1)
138
+ tzinfo (0.3.33)
139
+ watchr (0.7)
140
+ with_model (0.2.6)
141
+ activerecord (>= 2.3.5, < 4.0.0)
142
+ rspec (< 3)
143
+ xpath (0.1.4)
144
+ nokogiri (~> 1.3)
145
+
146
+ PLATFORMS
147
+ ruby
148
+
149
+ DEPENDENCIES
150
+ bundler (>= 1.0.0)
151
+ capybara (>= 0.4.0)
152
+ database_cleaner
153
+ factory_girl_rails
154
+ generator_spec
155
+ jeweler (>= 1.8.3)
156
+ minitest
157
+ rails (>= 3.2.0)
158
+ rdoc (~> 3.12)
159
+ rspec-rails (>= 2.8.0)
160
+ simplecov
161
+ spork (~> 1.0rc)
162
+ sqlite3
163
+ sqlite3-ruby
164
+ watchr
165
+ with_model (>= 0.1.5)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ REA
2
+ ===
3
+
4
+ Rails Engine for MDA pattern Resource Event Agent
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rdoc/task'
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task :default => :spec
18
+
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'REA'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README.md')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
28
+ load 'rails/tasks/engine.rake'
29
+
30
+ Bundler::GemHelper.install_tasks
31
+
32
+ task :default => :spec
33
+
34
+ require 'jeweler'
35
+ Jeweler::Tasks.new do |gem|
36
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
37
+ gem.name = "engine-rea"
38
+ gem.homepage = "http://github.com/lazing/rea"
39
+ gem.license = "MIT"
40
+ gem.summary = %Q{Rails Engine for MDA pattern Resource Event Agent}
41
+ gem.description = %Q{
42
+ follow REA model
43
+ }
44
+ gem.email = "lazing@gmail.com"
45
+ gem.authors = ["Ryan Wong"]
46
+ # dependencies defined in Gemfile
47
+ end
48
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
File without changes
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module Rea
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Rea
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ module Rea
2
+ class Category < ActiveRecord::Base
3
+ belongs_to :category_type
4
+ belongs_to :parent_category, :class_name=>self.name
5
+ has_many :child_categories, :class_name=>self.name
6
+ attr_accessible :name
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Rea
2
+ class CategoryMember < ActiveRecord::Base
3
+ # attr_accessible :title, :body
4
+ belongs_to :category
5
+ belongs_to :entity, :polymorphic=>true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rea
2
+ class CategoryType < ActiveRecord::Base
3
+ belongs_to :group, :polymorphic=>true
4
+ has_many :categories
5
+ attr_accessible :group_type, :name, :system, :automatic, :multiple
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Rea
2
+ class Group < ActiveRecord::Base
3
+ attr_accessible :name, :entity_types
4
+ has_many :category_types
5
+ has_many :group_entities
6
+
7
+ scope :groups, proc { |model_klass|
8
+ where("entity_types like ?", "%#{model_klass.name}%")
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Rea
2
+ class GroupEntity < ActiveRecord::Base
3
+ # attr_accessible :title, :body
4
+ belongs_to :group
5
+ belongs_to :entity, :polymorphic=>true
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ require 'thread'
2
+ module Rea
3
+ class Identifier < ActiveRecord::Base
4
+ attr_accessible :name, :value_reset_rule, :id_rule
5
+ SEM = Mutex.new
6
+
7
+ validates_presence_of :name, :id_rule
8
+ validate :instance_validations
9
+
10
+ def generate
11
+ SEM.synchronize do
12
+ self.class.transaction do
13
+ if value_reset_rule
14
+ self.last_value = 0 if self.instance_eval(value_reset_rule)
15
+ end
16
+ self.last_value = (self.last_value) || 0
17
+ self.last_value = self.last_value + 1
18
+ self.save!
19
+ self.instance_eval "\"#{id_rule}\""
20
+ end
21
+ end
22
+ end
23
+
24
+ protected
25
+ def instance_validations
26
+ if id_rule
27
+ begin
28
+ self.instance_eval "\"#{id_rule}\""
29
+ rescue Exception => e
30
+ errors.add :id_rule, :malformed, :error_message=> e.message
31
+ end
32
+ end
33
+ if value_reset_rule
34
+ begin
35
+ self.instance_eval value_reset_rule
36
+ rescue Exception => e
37
+ errors.add :value_reset_rule, :malformed, :error_message=> e.message
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Rea</title>
5
+ <%= stylesheet_link_tag "rea/application", :media => "all" %>
6
+ <%= javascript_include_tag "rea/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rea::Engine.routes.draw do
2
+ end
@@ -0,0 +1,13 @@
1
+ class CreateReaCategoryTypes < ActiveRecord::Migration
2
+ def change
3
+ create_table :rea_category_types do |t|
4
+ t.string :name
5
+ t.references :group
6
+ t.string :group_type
7
+ t.boolean :system
8
+ t.boolean :automatic
9
+ t.boolean :multiple
10
+ end
11
+ add_index :rea_category_types, [:group_id, :group_type]
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class CreateReaCategories < ActiveRecord::Migration
2
+ def change
3
+ create_table :rea_categories do |t|
4
+ t.string :name
5
+ t.references :category_type
6
+ t.references :category
7
+ t.timestamps
8
+ end
9
+ add_index :rea_categories, :category_type_id
10
+ add_index :rea_categories, :category_id
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class CreateReaCategoryMembers < ActiveRecord::Migration
2
+ def change
3
+ create_table :rea_category_members do |t|
4
+ t.references :entity
5
+ t.string :entity_type
6
+ t.references :category
7
+ t.timestamps
8
+ end
9
+ add_index :rea_category_members, [:entity_id, :entity_type]
10
+ add_index :rea_category_members, :category_id
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class CreateReaGroups < ActiveRecord::Migration
2
+ def change
3
+ create_table :rea_groups do |t|
4
+ t.string :name
5
+ t.string :entity_types
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateReaGroupEntities < ActiveRecord::Migration
2
+ def change
3
+ create_table :rea_group_entities do |t|
4
+ t.references :entity
5
+ t.string :entity_type
6
+ t.references :group
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateReaIdentifiers < ActiveRecord::Migration
2
+ def change
3
+ create_table :rea_identifiers do |t|
4
+ t.string :name
5
+ t.string :value_reset_rule
6
+ t.string :id_rule
7
+ t.integer :last_value, :default=>0
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate install Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,20 @@
1
+ class Rea::InstallGenerator < Rails::Generators::Base
2
+ include Rails::Generators::Migration
3
+ source_root File.expand_path('../../../../../db/migrate', __FILE__)
4
+ def self.next_migration_number(path)
5
+ unless @prev_migration_nr
6
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
7
+ else
8
+ @prev_migration_nr += 1
9
+ end
10
+ @prev_migration_nr.to_s
11
+ end
12
+
13
+ def copy_migrations
14
+ base_path = Pathname.new(self.class.source_root)
15
+ Dir[File.join(self.class.source_root, '*.rb')].each do |full_path|
16
+ path = Pathname.new(full_path).relative_path_from(base_path).to_s
17
+ migration_template path, "db/migrate/"+path.gsub(/\d+_([\w\d\.]+)/, '\1')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,40 @@
1
+ module Rea
2
+ module Dsl
3
+ module Behavioral
4
+ def self.included base
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ def create_id_string
9
+ self.send("#{self.class.identifier_field}=", Rea::Identifier.find_last_by_name(self.class.identifier).try(:generate))
10
+ end
11
+
12
+ module ClassMethods
13
+ def classification name, options={}, &block
14
+ precontext = @context
15
+ @context = @context.category_types.find_or_create_by_name name, options
16
+ block.call if block_given?
17
+ @context = precontext
18
+ end
19
+
20
+ def category *category_names, &block
21
+ options = category_names.extract_options!
22
+ category_names.flatten.each do |name|
23
+ attr_name = @context.is_a?(Rea::Category) ? :child_categories : :categories
24
+ precontext = @context
25
+ @context = @context.send(attr_name).find_or_create_by_name name, options
26
+ block.call if block_given?
27
+ @context = precontext
28
+ end
29
+ end
30
+
31
+ def identification name, options={}
32
+ cattr_accessor :identifier, :identifier_field
33
+ self.identifier = name
34
+ self.identifier_field = options.delete(:identifier_field) || :sn
35
+ self.before_create :create_id_string
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end