engine-rea 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rea::MetaType::Event do
|
4
|
+
with_model :event do
|
5
|
+
table do |t|
|
6
|
+
end
|
7
|
+
model do
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
Rea.model do
|
13
|
+
entities do
|
14
|
+
event :event, :type=>:increment
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { Rea.context.symbol_table[:event] }
|
20
|
+
its(:type) { should == :increment }
|
21
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rea::MetaType::Group do
|
4
|
+
|
5
|
+
with_model :agent do
|
6
|
+
table do |t|
|
7
|
+
t.string :name
|
8
|
+
t.references :group
|
9
|
+
end
|
10
|
+
model do
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
with_model :group do
|
15
|
+
table do |t|
|
16
|
+
t.string :name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
before :each do
|
21
|
+
|
22
|
+
Rea.model do
|
23
|
+
entities do
|
24
|
+
group :group do
|
25
|
+
grouped :agent
|
26
|
+
end
|
27
|
+
agent :agent do
|
28
|
+
grouping :group, :class_name=>Group.name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context :syntax do
|
35
|
+
context :symbol do
|
36
|
+
context :group do
|
37
|
+
subject { Rea.context.symbol_table[:group] }
|
38
|
+
it { should == Group }
|
39
|
+
its(:entity_types) { should include :agent }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context :model do
|
45
|
+
before :each do
|
46
|
+
Agent.delete_all
|
47
|
+
Group.delete_all
|
48
|
+
Group.create! :name=>:group
|
49
|
+
2.times do
|
50
|
+
Agent.create! :name=>:agent, :group_id=>Group.last.id
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class SimpleResource
|
4
|
+
end
|
5
|
+
|
6
|
+
describe Rea::MetaType::Resource do
|
7
|
+
|
8
|
+
context :simple_resource_define do
|
9
|
+
with_model :event do
|
10
|
+
table do |t|
|
11
|
+
t.references :resource
|
12
|
+
t.references :provider
|
13
|
+
t.decimal :amount
|
14
|
+
end
|
15
|
+
model do
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
Rea.model do
|
21
|
+
entities do
|
22
|
+
resource :simple_resource, :entity_type=>:simple do
|
23
|
+
item :rp, :id=>1, :value=>1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context :class do
|
30
|
+
subject { SimpleResource }
|
31
|
+
its(:rp) { should be_a_kind_of SimpleResource }
|
32
|
+
its(:entity_type) { should == :simple }
|
33
|
+
it { subject.find(1).should be_a_kind_of SimpleResource }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context :active_record_resource_define do
|
38
|
+
with_model :resource do
|
39
|
+
table do |t|
|
40
|
+
t.string :name
|
41
|
+
t.decimal :value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
before(:each) do
|
46
|
+
Rea.model do
|
47
|
+
entities do
|
48
|
+
resource :resource
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
subject { Resource.new :name=>:name, :value=>1 }
|
54
|
+
it { should be_valid }
|
55
|
+
it :name_not_nil do
|
56
|
+
subject.name = nil
|
57
|
+
should_not be_valid
|
58
|
+
end
|
59
|
+
it :value_not_nil do
|
60
|
+
subject.value = nil
|
61
|
+
should_not be_valid
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/spec/rea/meta_type_spec.rb
CHANGED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rea::Model do
|
4
|
+
|
5
|
+
context Rea do
|
6
|
+
subject { Rea }
|
7
|
+
its(:context) { should be_a_kind_of Rea::Model::Context }
|
8
|
+
its(:public_methods) { should include :model }
|
9
|
+
it :call_model do
|
10
|
+
expect { |b|
|
11
|
+
Rea.model &b
|
12
|
+
}.to yield_control
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context Rea::Model::Context do
|
17
|
+
with_model :resource do
|
18
|
+
table do |t|
|
19
|
+
end
|
20
|
+
model do
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
with_model :event do
|
25
|
+
table do |t|
|
26
|
+
end
|
27
|
+
model do
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
with_model :agent do
|
32
|
+
table do |t|
|
33
|
+
end
|
34
|
+
model do
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
with_model :commitment do
|
39
|
+
table do |t|
|
40
|
+
end
|
41
|
+
model do
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
with_model :contract do
|
46
|
+
table do |t|
|
47
|
+
end
|
48
|
+
model do
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
before(:each) do
|
53
|
+
Rea.model do
|
54
|
+
entities do
|
55
|
+
resource :resource
|
56
|
+
event :event
|
57
|
+
agent :agent
|
58
|
+
commitment :commitment
|
59
|
+
contract Contract
|
60
|
+
end
|
61
|
+
|
62
|
+
processes do
|
63
|
+
exchange :process_trade do
|
64
|
+
outflow :event,:resource=>:resource, :provider=>:agent
|
65
|
+
inflow :event, :resource=>:resource, :recipient=>:agent
|
66
|
+
end
|
67
|
+
conversion :process_produce do
|
68
|
+
outflow :event,:resource=>:resource, :provider=>:agent
|
69
|
+
inflow :event, :resource=>:resource, :recipient=>:agent
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
subject { Rea.context }
|
75
|
+
its("symbol_table.keys") { should include *%W{resource event agent
|
76
|
+
commitment contract process_trade process_produce} }
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: engine-rea
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -290,42 +290,48 @@ files:
|
|
290
290
|
- app/models/rea/category_member.rb
|
291
291
|
- app/models/rea/category_type.rb
|
292
292
|
- app/models/rea/group.rb
|
293
|
-
- app/models/rea/
|
293
|
+
- app/models/rea/group_type.rb
|
294
294
|
- app/models/rea/identifier.rb
|
295
295
|
- app/views/layouts/rea/application.html.erb
|
296
|
+
- config/locales/en.yml
|
297
|
+
- config/locales/zh-CN.yml
|
296
298
|
- config/routes.rb
|
297
299
|
- db/migrate/20120601074531_create_rea_category_types.rb
|
298
300
|
- db/migrate/20120601074540_create_rea_categories.rb
|
299
301
|
- db/migrate/20120605023205_create_rea_category_members.rb
|
300
302
|
- db/migrate/20120605030658_create_rea_groups.rb
|
301
|
-
- db/migrate/20120605030708_create_rea_group_entities.rb
|
302
303
|
- db/migrate/20120605082028_create_rea_identifiers.rb
|
304
|
+
- db/migrate/20120717080004_create_rea_group_types.rb
|
303
305
|
- engine-rea.gemspec
|
304
306
|
- lib/engine-rea.rb
|
305
307
|
- lib/generators/rea/install/USAGE
|
306
308
|
- lib/generators/rea/install/install_generator.rb
|
309
|
+
- lib/rails_patch.rb
|
307
310
|
- lib/rea.rb
|
311
|
+
- lib/rea/application.rb
|
308
312
|
- lib/rea/aspect_type.rb
|
309
313
|
- lib/rea/aspect_type/base.rb
|
310
|
-
- lib/rea/aspect_type/
|
314
|
+
- lib/rea/aspect_type/classification.rb
|
311
315
|
- lib/rea/aspect_type/description.rb
|
312
|
-
- lib/rea/aspect_type/
|
313
|
-
- lib/rea/aspect_type/
|
314
|
-
- lib/rea/dsl.rb
|
315
|
-
- lib/rea/dsl/behavioral.rb
|
316
|
-
- lib/rea/dsl/structural.rb
|
316
|
+
- lib/rea/aspect_type/due_date.rb
|
317
|
+
- lib/rea/aspect_type/identification.rb
|
317
318
|
- lib/rea/engine.rb
|
318
319
|
- lib/rea/meta_type.rb
|
319
320
|
- lib/rea/meta_type/agent.rb
|
320
321
|
- lib/rea/meta_type/commitment.rb
|
321
322
|
- lib/rea/meta_type/contract.rb
|
323
|
+
- lib/rea/meta_type/conversion.rb
|
322
324
|
- lib/rea/meta_type/entity.rb
|
323
325
|
- lib/rea/meta_type/event.rb
|
326
|
+
- lib/rea/meta_type/exchange.rb
|
324
327
|
- lib/rea/meta_type/group.rb
|
328
|
+
- lib/rea/meta_type/process.rb
|
325
329
|
- lib/rea/meta_type/resource.rb
|
326
330
|
- lib/rea/meta_type/schedule.rb
|
327
331
|
- lib/rea/meta_type/type.rb
|
332
|
+
- lib/rea/model.rb
|
328
333
|
- lib/rea/plugins/active_model.rb
|
334
|
+
- lib/rea/settings.rb
|
329
335
|
- lib/tasks/cucumber.rake
|
330
336
|
- lib/tasks/rea_tasks.rake
|
331
337
|
- lib/tasks/watchr.rake
|
@@ -369,14 +375,25 @@ files:
|
|
369
375
|
- spec/models/rea/category_member_spec.rb
|
370
376
|
- spec/models/rea/category_spec.rb
|
371
377
|
- spec/models/rea/category_type_spec.rb
|
372
|
-
- spec/models/rea/group_entity_spec.rb
|
373
378
|
- spec/models/rea/group_spec.rb
|
379
|
+
- spec/models/rea/group_type_spec.rb
|
374
380
|
- spec/models/rea/identifier_spec.rb
|
375
|
-
- spec/rea/
|
376
|
-
- spec/rea/
|
377
|
-
- spec/rea/
|
381
|
+
- spec/rea/application_spec.rb
|
382
|
+
- spec/rea/aspect_type/classification_spec.rb
|
383
|
+
- spec/rea/aspect_type/due_date_spec.rb
|
384
|
+
- spec/rea/aspect_type/identification_spec.rb
|
385
|
+
- spec/rea/aspect_type_spec.rb
|
378
386
|
- spec/rea/engine_spec.rb
|
387
|
+
- spec/rea/meta_type/agent_spec.rb
|
388
|
+
- spec/rea/meta_type/commitment_spec.rb
|
389
|
+
- spec/rea/meta_type/contract_spec.rb
|
390
|
+
- spec/rea/meta_type/entity_spec.rb
|
391
|
+
- spec/rea/meta_type/event_spec.rb
|
392
|
+
- spec/rea/meta_type/group_spec.rb
|
393
|
+
- spec/rea/meta_type/process_spec.rb
|
394
|
+
- spec/rea/meta_type/resource_spec.rb
|
379
395
|
- spec/rea/meta_type_spec.rb
|
396
|
+
- spec/rea/model_spec.rb
|
380
397
|
- spec/spec_helper.rb
|
381
398
|
homepage: http://github.com/lazing/engine-rea
|
382
399
|
licenses:
|
@@ -393,7 +410,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
393
410
|
version: '0'
|
394
411
|
segments:
|
395
412
|
- 0
|
396
|
-
hash: -
|
413
|
+
hash: -1070606783
|
397
414
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
398
415
|
none: false
|
399
416
|
requirements:
|
@@ -1,75 +0,0 @@
|
|
1
|
-
module Rea
|
2
|
-
module AspectType
|
3
|
-
module Classification
|
4
|
-
def self.included base
|
5
|
-
base.extend ClassMethods
|
6
|
-
base.scope :by_category, lambda { |category_type_name, category_name|
|
7
|
-
$field_name = base.rea_ast[:classification][category_type_name.to_sym]
|
8
|
-
base.where($field_name.to_sym=>category_name)
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
def is category
|
13
|
-
$field_name = self.class.rea_ast[:classification][category.category_type.name.to_sym]
|
14
|
-
self.send($field_name).to_sym == category.name.to_sym
|
15
|
-
end
|
16
|
-
|
17
|
-
def is_in category
|
18
|
-
field_name = self.class.rea_ast[:classification][category.category_type.name.to_sym]
|
19
|
-
$current = category.class.find_by_name(self.send(field_name))
|
20
|
-
while($current) do
|
21
|
-
return true if $current.name.to_s == category.name.to_s
|
22
|
-
$current = $current.parent_category
|
23
|
-
end
|
24
|
-
return false
|
25
|
-
end
|
26
|
-
|
27
|
-
module CategoryType
|
28
|
-
def category *category_names, &block
|
29
|
-
options = category_names.extract_options!
|
30
|
-
category_names.flatten.each do |name|
|
31
|
-
category = self.categories.find_or_create_by_name name, options
|
32
|
-
block.call(category) if block_given?
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
module Category
|
38
|
-
def category *category_names, &block
|
39
|
-
options = category_names.extract_options!
|
40
|
-
options = {:category_type_id=>self.category_type_id, :category_id=>self.id}.merge(options)
|
41
|
-
category_names.flatten.each do |name|
|
42
|
-
category = self.child_categories.find_or_create_by_name name, options
|
43
|
-
block.call(category) if block_given?
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
module ClassMethods
|
49
|
-
def category_type category_type_name, options={}, &block
|
50
|
-
category_type = ::Rea::CategoryType.find_or_create_by_name category_type_name, options
|
51
|
-
block.call(category_type) if block_given?
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
def member name, options={}
|
56
|
-
options = { :name=>name.to_s }.merge options
|
57
|
-
rea[name] = ::Rea::AspectType::MemberType.new options
|
58
|
-
rea_ast[:classification][options[:type]] = name
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
class ClassificationAspect < Base
|
63
|
-
end
|
64
|
-
|
65
|
-
class MemberType < Base
|
66
|
-
attr_reader :name, :type
|
67
|
-
|
68
|
-
def category_options
|
69
|
-
category_type = ::Rea::CategoryType.find_by_name(self.type.to_s)
|
70
|
-
category_type.categories
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|