engine-rea 0.2.1 → 0.2.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.
- data/VERSION +1 -1
- data/app/models/rea/category.rb +4 -0
- data/app/models/rea/category_member.rb +1 -0
- data/app/models/rea/category_type.rb +1 -1
- data/app/models/rea/group.rb +17 -6
- data/app/models/rea/group_type.rb +7 -0
- data/app/models/rea/identifier.rb +12 -3
- data/config/locales/en.yml +4 -0
- data/config/locales/zh-CN.yml +42 -0
- data/db/migrate/20120601074531_create_rea_category_types.rb +1 -1
- data/db/migrate/20120601074540_create_rea_categories.rb +1 -1
- data/db/migrate/20120605030658_create_rea_groups.rb +14 -3
- data/db/migrate/20120605082028_create_rea_identifiers.rb +2 -2
- data/db/migrate/20120717080004_create_rea_group_types.rb +7 -0
- data/engine-rea.gemspec +31 -14
- data/lib/generators/rea/install/install_generator.rb +8 -0
- data/lib/rails_patch.rb +26 -0
- data/lib/rea.rb +25 -1
- data/lib/rea/application.rb +86 -0
- data/lib/rea/aspect_type.rb +28 -6
- data/lib/rea/aspect_type/base.rb +3 -2
- data/lib/rea/aspect_type/classification.rb +142 -0
- data/lib/rea/aspect_type/description.rb +3 -2
- data/lib/rea/aspect_type/due_date.rb +34 -0
- data/lib/rea/aspect_type/identification.rb +38 -0
- data/lib/rea/engine.rb +1 -3
- data/lib/rea/meta_type.rb +1 -1
- data/lib/rea/meta_type/agent.rb +1 -1
- data/lib/rea/meta_type/commitment.rb +5 -6
- data/lib/rea/meta_type/contract.rb +17 -4
- data/lib/rea/meta_type/conversion.rb +6 -0
- data/lib/rea/meta_type/entity.rb +61 -20
- data/lib/rea/meta_type/event.rb +17 -24
- data/lib/rea/meta_type/exchange.rb +6 -0
- data/lib/rea/meta_type/group.rb +25 -0
- data/lib/rea/meta_type/process.rb +28 -0
- data/lib/rea/meta_type/resource.rb +5 -1
- data/lib/rea/model.rb +65 -0
- data/lib/rea/settings.rb +58 -0
- data/spec/dummy/db/schema.rb +1 -56
- data/spec/generators/rea/install/install_generator_spec.rb +2 -0
- data/spec/models/rea/category_member_spec.rb +5 -1
- data/spec/models/rea/category_spec.rb +19 -1
- data/spec/models/rea/category_type_spec.rb +24 -1
- data/spec/models/rea/group_spec.rb +34 -1
- data/spec/models/rea/group_type_spec.rb +8 -0
- data/spec/rea/application_spec.rb +8 -0
- data/spec/rea/aspect_type/classification_spec.rb +107 -0
- data/spec/rea/aspect_type/due_date_spec.rb +75 -0
- data/spec/rea/aspect_type/identification_spec.rb +64 -0
- data/spec/rea/aspect_type_spec.rb +44 -0
- data/spec/rea/engine_spec.rb +0 -3
- data/spec/rea/meta_type/agent_spec.rb +28 -0
- data/spec/rea/meta_type/commitment_spec.rb +45 -0
- data/spec/rea/meta_type/contract_spec.rb +42 -0
- data/spec/rea/meta_type/entity_spec.rb +58 -0
- data/spec/rea/meta_type/event_spec.rb +21 -0
- data/spec/rea/meta_type/group_spec.rb +55 -0
- data/spec/rea/meta_type/process_spec.rb +5 -0
- data/spec/rea/meta_type/resource_spec.rb +65 -0
- data/spec/rea/meta_type_spec.rb +1 -1
- data/spec/rea/model_spec.rb +79 -0
- metadata +32 -15
- data/app/models/rea/group_entity.rb +0 -7
- data/db/migrate/20120605030708_create_rea_group_entities.rb +0 -9
- data/lib/rea/aspect_type/classification_aspect.rb +0 -75
- data/lib/rea/aspect_type/due_date_type.rb +0 -5
- data/lib/rea/aspect_type/identifier_setup.rb +0 -7
- data/lib/rea/dsl.rb +0 -24
- data/lib/rea/dsl/behavioral.rb +0 -50
- data/lib/rea/dsl/structural.rb +0 -53
- data/spec/models/rea/group_entity_spec.rb +0 -5
- data/spec/rea/dsl/behavioral_spec.rb +0 -149
- data/spec/rea/dsl/structural_spec.rb +0 -299
- data/spec/rea/dsl_spec.rb +0 -11
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/app/models/rea/category.rb
CHANGED
@@ -2,8 +2,12 @@ module Rea
|
|
2
2
|
class Category < ActiveRecord::Base
|
3
3
|
include ::Rea::AspectType::Classification::Category
|
4
4
|
belongs_to :category_type
|
5
|
+
has_many :category_members, :class_name=>::Rea::CategoryMember.name
|
5
6
|
belongs_to :parent_category, :class_name=>self.name, :foreign_key=>:category_id
|
6
7
|
has_many :child_categories, :class_name=>self.name
|
8
|
+
has_and_belongs_to_many :groups
|
9
|
+
|
7
10
|
attr_accessible :name, :category_type_id, :category_id
|
11
|
+
|
8
12
|
end
|
9
13
|
end
|
data/app/models/rea/group.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
1
|
module Rea
|
2
2
|
class Group < ActiveRecord::Base
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
attr_accessor :category_ids_csv
|
4
|
+
attr_accessible :name, :group_type_id, :category_ids_csv
|
5
|
+
has_and_belongs_to_many :categories
|
6
|
+
belongs_to :group_type
|
7
|
+
has_many :category_types, :through=>:categories
|
8
|
+
|
9
|
+
before_validation do
|
10
|
+
logger.debug "before validation" + self.category_ids_csv
|
11
|
+
return unless self.category_ids_csv
|
12
|
+
ids = self.category_ids_csv.split(/,/)
|
13
|
+
ids = ids.delete_if { |id| id =~ /T/ }
|
14
|
+
self.category_ids = ids
|
15
|
+
end
|
16
|
+
|
17
|
+
def category_ids_csv
|
18
|
+
@category_ids_csv ||= category_ids.join ','
|
19
|
+
end
|
6
20
|
|
7
|
-
scope :groups, proc { |model_klass|
|
8
|
-
where("entity_types like ?", "%#{model_klass.name}%")
|
9
|
-
}
|
10
21
|
end
|
11
22
|
end
|
@@ -1,12 +1,20 @@
|
|
1
1
|
require 'thread'
|
2
2
|
module Rea
|
3
3
|
class Identifier < ActiveRecord::Base
|
4
|
-
attr_accessible :name, :value_reset_rule, :id_rule
|
4
|
+
attr_accessible :name, :value_reset_rule, :id_rule, :last_value
|
5
5
|
SEM = Mutex.new
|
6
6
|
|
7
7
|
validates_presence_of :name, :id_rule
|
8
8
|
validate :instance_validations
|
9
9
|
|
10
|
+
def next_id
|
11
|
+
self.instance_eval "\"#{id_rule}\"" if id_rule
|
12
|
+
end
|
13
|
+
|
14
|
+
def next_value
|
15
|
+
last_value + 1
|
16
|
+
end
|
17
|
+
|
10
18
|
def generate
|
11
19
|
SEM.synchronize do
|
12
20
|
self.class.transaction do
|
@@ -14,9 +22,10 @@ module Rea
|
|
14
22
|
self.last_value = 0 if self.instance_eval(value_reset_rule)
|
15
23
|
end
|
16
24
|
self.last_value = (self.last_value) || 0
|
17
|
-
|
25
|
+
id = self.instance_eval "\"#{id_rule}\""
|
26
|
+
self.last_value = next_value
|
18
27
|
self.save!
|
19
|
-
|
28
|
+
return id
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
zh-CN:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
rea/category_type:
|
5
|
+
one: "分类类型"
|
6
|
+
other: "分类类型"
|
7
|
+
rea/category:
|
8
|
+
one: "分类"
|
9
|
+
other: "分类"
|
10
|
+
rea/identifier:
|
11
|
+
one: "标识码"
|
12
|
+
other: "标识码"
|
13
|
+
rea/group:
|
14
|
+
one: "分组"
|
15
|
+
other: "分组"
|
16
|
+
rea/group_type:
|
17
|
+
one: "分组类型"
|
18
|
+
other: "分组类型"
|
19
|
+
|
20
|
+
attributes:
|
21
|
+
rea/category_type:
|
22
|
+
name: "名称"
|
23
|
+
categories: "分类"
|
24
|
+
rea/category:
|
25
|
+
name: "名称"
|
26
|
+
category_type: "分类类型"
|
27
|
+
parent_category: "上级分类"
|
28
|
+
rea/identifier:
|
29
|
+
name: "名称"
|
30
|
+
value_reset_rule: "值重置规则"
|
31
|
+
id_rule: "标识码规则"
|
32
|
+
last_value: "最新值"
|
33
|
+
next_id: "下一标识"
|
34
|
+
created_at: "创建时间"
|
35
|
+
updated_at: "更新时间"
|
36
|
+
|
37
|
+
errors:
|
38
|
+
models:
|
39
|
+
rea/identifier:
|
40
|
+
attributes:
|
41
|
+
id_rule:
|
42
|
+
malformed: "标识符格式不正确: %{error_message}"
|
@@ -1,9 +1,20 @@
|
|
1
1
|
class CreateReaGroups < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :rea_groups do |t|
|
4
|
-
t.string :name
|
5
|
-
t.
|
6
|
-
t.timestamps
|
4
|
+
t.string :name, :null=>false
|
5
|
+
t.references :group_type
|
7
6
|
end
|
7
|
+
|
8
|
+
add_index :rea_groups, :group_type_id
|
9
|
+
|
10
|
+
create_table :categories_groups do |t|
|
11
|
+
t.references :category
|
12
|
+
t.references :group
|
13
|
+
end
|
14
|
+
|
15
|
+
add_index :categories_groups, :group_id
|
16
|
+
add_index :categories_groups, :category_id
|
17
|
+
|
18
|
+
|
8
19
|
end
|
9
20
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class CreateReaIdentifiers < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :rea_identifiers do |t|
|
4
|
-
t.string :name
|
4
|
+
t.string :name, :null=>false
|
5
5
|
t.string :value_reset_rule
|
6
|
-
t.string :id_rule
|
6
|
+
t.string :id_rule, :null=>false
|
7
7
|
t.integer :last_value, :default=>0
|
8
8
|
t.timestamps
|
9
9
|
end
|
data/engine-rea.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "engine-rea"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ryan Wong"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-07-18"
|
13
13
|
s.description = "\n follow REA model\n\t"
|
14
14
|
s.email = "lazing@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,42 +32,48 @@ Gem::Specification.new do |s|
|
|
32
32
|
"app/models/rea/category_member.rb",
|
33
33
|
"app/models/rea/category_type.rb",
|
34
34
|
"app/models/rea/group.rb",
|
35
|
-
"app/models/rea/
|
35
|
+
"app/models/rea/group_type.rb",
|
36
36
|
"app/models/rea/identifier.rb",
|
37
37
|
"app/views/layouts/rea/application.html.erb",
|
38
|
+
"config/locales/en.yml",
|
39
|
+
"config/locales/zh-CN.yml",
|
38
40
|
"config/routes.rb",
|
39
41
|
"db/migrate/20120601074531_create_rea_category_types.rb",
|
40
42
|
"db/migrate/20120601074540_create_rea_categories.rb",
|
41
43
|
"db/migrate/20120605023205_create_rea_category_members.rb",
|
42
44
|
"db/migrate/20120605030658_create_rea_groups.rb",
|
43
|
-
"db/migrate/20120605030708_create_rea_group_entities.rb",
|
44
45
|
"db/migrate/20120605082028_create_rea_identifiers.rb",
|
46
|
+
"db/migrate/20120717080004_create_rea_group_types.rb",
|
45
47
|
"engine-rea.gemspec",
|
46
48
|
"lib/engine-rea.rb",
|
47
49
|
"lib/generators/rea/install/USAGE",
|
48
50
|
"lib/generators/rea/install/install_generator.rb",
|
51
|
+
"lib/rails_patch.rb",
|
49
52
|
"lib/rea.rb",
|
53
|
+
"lib/rea/application.rb",
|
50
54
|
"lib/rea/aspect_type.rb",
|
51
55
|
"lib/rea/aspect_type/base.rb",
|
52
|
-
"lib/rea/aspect_type/
|
56
|
+
"lib/rea/aspect_type/classification.rb",
|
53
57
|
"lib/rea/aspect_type/description.rb",
|
54
|
-
"lib/rea/aspect_type/
|
55
|
-
"lib/rea/aspect_type/
|
56
|
-
"lib/rea/dsl.rb",
|
57
|
-
"lib/rea/dsl/behavioral.rb",
|
58
|
-
"lib/rea/dsl/structural.rb",
|
58
|
+
"lib/rea/aspect_type/due_date.rb",
|
59
|
+
"lib/rea/aspect_type/identification.rb",
|
59
60
|
"lib/rea/engine.rb",
|
60
61
|
"lib/rea/meta_type.rb",
|
61
62
|
"lib/rea/meta_type/agent.rb",
|
62
63
|
"lib/rea/meta_type/commitment.rb",
|
63
64
|
"lib/rea/meta_type/contract.rb",
|
65
|
+
"lib/rea/meta_type/conversion.rb",
|
64
66
|
"lib/rea/meta_type/entity.rb",
|
65
67
|
"lib/rea/meta_type/event.rb",
|
68
|
+
"lib/rea/meta_type/exchange.rb",
|
66
69
|
"lib/rea/meta_type/group.rb",
|
70
|
+
"lib/rea/meta_type/process.rb",
|
67
71
|
"lib/rea/meta_type/resource.rb",
|
68
72
|
"lib/rea/meta_type/schedule.rb",
|
69
73
|
"lib/rea/meta_type/type.rb",
|
74
|
+
"lib/rea/model.rb",
|
70
75
|
"lib/rea/plugins/active_model.rb",
|
76
|
+
"lib/rea/settings.rb",
|
71
77
|
"lib/tasks/cucumber.rake",
|
72
78
|
"lib/tasks/rea_tasks.rake",
|
73
79
|
"lib/tasks/watchr.rake",
|
@@ -111,14 +117,25 @@ Gem::Specification.new do |s|
|
|
111
117
|
"spec/models/rea/category_member_spec.rb",
|
112
118
|
"spec/models/rea/category_spec.rb",
|
113
119
|
"spec/models/rea/category_type_spec.rb",
|
114
|
-
"spec/models/rea/group_entity_spec.rb",
|
115
120
|
"spec/models/rea/group_spec.rb",
|
121
|
+
"spec/models/rea/group_type_spec.rb",
|
116
122
|
"spec/models/rea/identifier_spec.rb",
|
117
|
-
"spec/rea/
|
118
|
-
"spec/rea/
|
119
|
-
"spec/rea/
|
123
|
+
"spec/rea/application_spec.rb",
|
124
|
+
"spec/rea/aspect_type/classification_spec.rb",
|
125
|
+
"spec/rea/aspect_type/due_date_spec.rb",
|
126
|
+
"spec/rea/aspect_type/identification_spec.rb",
|
127
|
+
"spec/rea/aspect_type_spec.rb",
|
120
128
|
"spec/rea/engine_spec.rb",
|
129
|
+
"spec/rea/meta_type/agent_spec.rb",
|
130
|
+
"spec/rea/meta_type/commitment_spec.rb",
|
131
|
+
"spec/rea/meta_type/contract_spec.rb",
|
132
|
+
"spec/rea/meta_type/entity_spec.rb",
|
133
|
+
"spec/rea/meta_type/event_spec.rb",
|
134
|
+
"spec/rea/meta_type/group_spec.rb",
|
135
|
+
"spec/rea/meta_type/process_spec.rb",
|
136
|
+
"spec/rea/meta_type/resource_spec.rb",
|
121
137
|
"spec/rea/meta_type_spec.rb",
|
138
|
+
"spec/rea/model_spec.rb",
|
122
139
|
"spec/spec_helper.rb"
|
123
140
|
]
|
124
141
|
s.homepage = "http://github.com/lazing/engine-rea"
|
@@ -17,4 +17,12 @@ class Rea::InstallGenerator < Rails::Generators::Base
|
|
17
17
|
migration_template path, "db/migrate/"+path.gsub(/\d+_([\w\d\.]+)/, '\1')
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
def install_rea_initializer
|
22
|
+
initializer "rea.rb" do |data|
|
23
|
+
data = ""
|
24
|
+
data << "Rea.setup do |application|\n"
|
25
|
+
data << "end"
|
26
|
+
end
|
27
|
+
end
|
20
28
|
end
|
data/lib/rails_patch.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module AutosaveAssociation
|
3
|
+
def save_belongs_to_association(reflection)
|
4
|
+
association = association_instance_get(reflection.name)
|
5
|
+
record = association && association.load_target
|
6
|
+
return if record.is_a? Array
|
7
|
+
if record && !record.destroyed?
|
8
|
+
autosave = reflection.options[:autosave]
|
9
|
+
|
10
|
+
if autosave && record.marked_for_destruction?
|
11
|
+
record.destroy
|
12
|
+
elsif autosave != false
|
13
|
+
saved = record.save(:validate => !autosave) if record.new_record? || (autosave && record.changed_for_autosave?)
|
14
|
+
|
15
|
+
if association.updated?
|
16
|
+
association_id = record.send(reflection.options[:primary_key] || :id)
|
17
|
+
self[reflection.foreign_key] = association_id
|
18
|
+
association.loaded!
|
19
|
+
end
|
20
|
+
|
21
|
+
saved if autosave
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/rea.rb
CHANGED
@@ -1,13 +1,37 @@
|
|
1
1
|
require "rea/engine"
|
2
2
|
|
3
|
+
require 'rails_patch'
|
4
|
+
|
3
5
|
module Rea
|
4
|
-
autoload :
|
6
|
+
autoload :Model, 'rea/model'
|
5
7
|
autoload :InstallGenerator, 'generators/rea/install/install_generator'
|
6
8
|
|
7
9
|
autoload :AspectType, 'rea/aspect_type'
|
8
10
|
autoload :MetaType, 'rea/meta_type'
|
9
11
|
|
12
|
+
autoload :Settings, 'rea/settings'
|
13
|
+
autoload :Application, 'rea/application'
|
14
|
+
|
10
15
|
module Plugins
|
11
16
|
autoload :ActiveModel, 'rea/plugins/active_model'
|
12
17
|
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
|
21
|
+
attr_accessor :application
|
22
|
+
|
23
|
+
def application
|
24
|
+
@application ||= ::Rea::Application.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup
|
28
|
+
puts "Loading Engine-Rea........"
|
29
|
+
application.setup!
|
30
|
+
yield(application)
|
31
|
+
application.prepare!
|
32
|
+
end
|
33
|
+
|
34
|
+
delegate :model, :to=>:application
|
35
|
+
delegate :context, :to=>:application
|
36
|
+
end
|
13
37
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Rea
|
2
|
+
class Application
|
3
|
+
include ::Rea::Settings
|
4
|
+
include ::Rea::Model
|
5
|
+
|
6
|
+
setting :load_paths, [File.expand_path('app/rea', Rails.root)]
|
7
|
+
|
8
|
+
def setup!
|
9
|
+
end
|
10
|
+
|
11
|
+
def prepare!
|
12
|
+
remove_active_admin_load_paths_from_rails_autoload_and_eager_load
|
13
|
+
attach_reloader
|
14
|
+
load!
|
15
|
+
end
|
16
|
+
|
17
|
+
def loaded?
|
18
|
+
@@loaded ||= false
|
19
|
+
end
|
20
|
+
|
21
|
+
def load!
|
22
|
+
return if loaded?
|
23
|
+
# Load files
|
24
|
+
files_in_load_path.each{|file| load file }
|
25
|
+
@@loaded = true
|
26
|
+
end
|
27
|
+
|
28
|
+
def unload!
|
29
|
+
@@loaded = false
|
30
|
+
end
|
31
|
+
|
32
|
+
def files_in_load_path
|
33
|
+
load_paths.flatten.compact.uniq.collect{|path| Dir["#{path}/**/*.rb"] }.flatten
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
private
|
38
|
+
# Since we're dealing with all our own file loading, we need
|
39
|
+
# # to remove our paths from the ActiveSupport autoload paths.
|
40
|
+
# # If not, file naming becomes very important and can cause clashes.
|
41
|
+
def remove_active_admin_load_paths_from_rails_autoload_and_eager_load
|
42
|
+
ActiveSupport::Dependencies.autoload_paths.reject!{|path|
|
43
|
+
load_paths.include?(path) }
|
44
|
+
# Don't eagerload our configs, we'll deal with them ourselves
|
45
|
+
Rails.application.config.eager_load_paths = Rails.application.config.eager_load_paths.reject do |path|
|
46
|
+
load_paths.include?(path)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def attach_reloader
|
51
|
+
Rails32Reloader.new(Rails.application, Rea.application).attach!
|
52
|
+
end
|
53
|
+
|
54
|
+
class Rails32Reloader
|
55
|
+
attr_reader :rea_app, :rails_app, :rails_version
|
56
|
+
|
57
|
+
def initialize(rails_app, rea_app, rails_version = "3.2")
|
58
|
+
@rails_app = rails_app
|
59
|
+
@rea_app = rea_app
|
60
|
+
@rails_version = rails_version.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
def attach!
|
64
|
+
rea_app.load_paths.each do |path|
|
65
|
+
rails_app.config.watchable_dirs[path] = [:rb]
|
66
|
+
end
|
67
|
+
|
68
|
+
reloader = self
|
69
|
+
|
70
|
+
ActionDispatch::Reloader.to_prepare do
|
71
|
+
reloader.reload!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def reload!
|
76
|
+
rea_app.unload!
|
77
|
+
rea_app.load!
|
78
|
+
end
|
79
|
+
|
80
|
+
def major_rails_version
|
81
|
+
@rails_version[0..2]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|