engine-rea 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile +3 -2
  3. data/Gemfile.lock +40 -35
  4. data/VERSION +1 -1
  5. data/app/models/rea/categories_entity.rb +7 -0
  6. data/app/models/rea/category.rb +18 -7
  7. data/app/models/rea/classification.rb +7 -0
  8. data/app/models/rea/entities_group.rb +7 -0
  9. data/app/models/rea/group.rb +5 -17
  10. data/app/models/rea/rea.rb +7 -0
  11. data/config/locales/en.yml +2 -0
  12. data/config/locales/zh-CN.yml +16 -17
  13. data/db/migrate/20121129100245_create_rea_groups.rb +18 -0
  14. data/db/migrate/20121129100748_create_rea_categories.rb +19 -0
  15. data/db/migrate/20121129101744_create_rea_classifications.rb +29 -0
  16. data/db/migrate/20121130051633_create_rea_entities_groups.rb +13 -0
  17. data/db/migrate/20121130100600_create_rea_categories_entities.rb +13 -0
  18. data/engine-rea.gemspec +27 -59
  19. data/lib/generators/rea/install/install_generator.rb +4 -4
  20. data/lib/rea/active_record_ext.rb +82 -0
  21. data/lib/rea/application.rb +55 -21
  22. data/lib/rea/engine.rb +8 -2
  23. data/lib/rea.rb +5 -10
  24. data/spec/dummy/db/schema.rb +61 -1
  25. data/spec/models/rea/categories_entity_spec.rb +7 -0
  26. data/spec/models/rea/category_spec.rb +10 -19
  27. data/spec/models/rea/classification_spec.rb +6 -0
  28. data/spec/models/rea/entities_group_spec.rb +7 -0
  29. data/spec/models/rea/group_spec.rb +3 -35
  30. data/spec/rea/active_record_ext_spec.rb +35 -0
  31. data/spec/rea/application_spec.rb +17 -0
  32. data/spec/spec_helper.rb +3 -0
  33. metadata +40 -59
  34. data/app/models/rea/category_member.rb +0 -8
  35. data/app/models/rea/category_type.rb +0 -7
  36. data/app/models/rea/group_type.rb +0 -7
  37. data/app/models/rea/identifier.rb +0 -51
  38. data/app/views/layouts/rea/application.html.erb +0 -14
  39. data/db/migrate/20120601074531_create_rea_category_types.rb +0 -11
  40. data/db/migrate/20120601074540_create_rea_categories.rb +0 -12
  41. data/db/migrate/20120605023205_create_rea_category_members.rb +0 -12
  42. data/db/migrate/20120605030658_create_rea_groups.rb +0 -20
  43. data/db/migrate/20120605082028_create_rea_identifiers.rb +0 -11
  44. data/db/migrate/20120717080004_create_rea_group_types.rb +0 -7
  45. data/lib/rea/aspect_type/base.rb +0 -10
  46. data/lib/rea/aspect_type/classification.rb +0 -142
  47. data/lib/rea/aspect_type/description.rb +0 -8
  48. data/lib/rea/aspect_type/due_date.rb +0 -34
  49. data/lib/rea/aspect_type/identification.rb +0 -38
  50. data/lib/rea/aspect_type.rb +0 -33
  51. data/lib/rea/meta_type/agent.rb +0 -10
  52. data/lib/rea/meta_type/commitment.rb +0 -26
  53. data/lib/rea/meta_type/contract.rb +0 -32
  54. data/lib/rea/meta_type/conversion.rb +0 -6
  55. data/lib/rea/meta_type/entity.rb +0 -91
  56. data/lib/rea/meta_type/event.rb +0 -39
  57. data/lib/rea/meta_type/exchange.rb +0 -6
  58. data/lib/rea/meta_type/group.rb +0 -25
  59. data/lib/rea/meta_type/process.rb +0 -28
  60. data/lib/rea/meta_type/resource.rb +0 -14
  61. data/lib/rea/meta_type/schedule.rb +0 -0
  62. data/lib/rea/meta_type/type.rb +0 -0
  63. data/lib/rea/meta_type.rb +0 -8
  64. data/lib/rea/model.rb +0 -65
  65. data/lib/rea/plugins/active_model.rb +0 -18
  66. data/spec/models/rea/category_member_spec.rb +0 -9
  67. data/spec/models/rea/category_type_spec.rb +0 -28
  68. data/spec/models/rea/group_type_spec.rb +0 -8
  69. data/spec/models/rea/identifier_spec.rb +0 -48
  70. data/spec/rea/aspect_type/classification_spec.rb +0 -107
  71. data/spec/rea/aspect_type/due_date_spec.rb +0 -75
  72. data/spec/rea/aspect_type/identification_spec.rb +0 -64
  73. data/spec/rea/aspect_type_spec.rb +0 -44
  74. data/spec/rea/meta_type/agent_spec.rb +0 -28
  75. data/spec/rea/meta_type/commitment_spec.rb +0 -45
  76. data/spec/rea/meta_type/contract_spec.rb +0 -42
  77. data/spec/rea/meta_type/entity_spec.rb +0 -58
  78. data/spec/rea/meta_type/event_spec.rb +0 -21
  79. data/spec/rea/meta_type/group_spec.rb +0 -55
  80. data/spec/rea/meta_type/process_spec.rb +0 -5
  81. data/spec/rea/meta_type/resource_spec.rb +0 -65
  82. data/spec/rea/meta_type_spec.rb +0 -11
  83. data/spec/rea/model_spec.rb +0 -79
@@ -1,25 +0,0 @@
1
- module Rea
2
- module MetaType
3
- module Group
4
- def self.included base
5
- base.fields = [:name]
6
- base.send :include, Entity
7
- base.extend ClassMethods
8
- end
9
-
10
- module ClassMethods
11
-
12
- def entity_types
13
- @@entity_types ||= []
14
- end
15
-
16
- def grouped *names
17
- $options = names.extract_options!
18
- names.each do |name|
19
- entity_types << name
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,28 +0,0 @@
1
- module Rea
2
- module MetaType
3
- class Process
4
-
5
- def inflows
6
- @inflows ||= []
7
- end
8
-
9
- def outflows
10
- @outflows ||= []
11
- end
12
-
13
- def inflow *names, &block
14
- $options = names.extract_options!
15
- names.each do |name|
16
- inflows << name
17
- end
18
- end
19
-
20
- def outflow *names, &block
21
- $options = names.extract_options!
22
- names.each do |name|
23
- outflows << name
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,14 +0,0 @@
1
- module Rea
2
- module MetaType
3
- module Resource
4
- def self.included base
5
- base.fields = [:name, :value]
6
- base.send :include, Entity
7
- base.extend ClassMethod
8
- end
9
-
10
- module ClassMethod
11
- end
12
- end
13
- end
14
- end
File without changes
File without changes
data/lib/rea/meta_type.rb DELETED
@@ -1,8 +0,0 @@
1
- module Rea
2
- module MetaType
3
-
4
- %w{entity resource event agent commitment contract group type schedule process exchange conversion}.each do |name|
5
- autoload name.camelize.to_sym, "rea/meta_type/#{name}"
6
- end
7
- end
8
- end
data/lib/rea/model.rb DELETED
@@ -1,65 +0,0 @@
1
- module Rea
2
- module Model
3
- class Context
4
-
5
- def entities &block
6
- instance_eval &block
7
- end
8
-
9
- %W{resource event agent commitment contract group}.each do |type_name|
10
- define_method type_name do |*names, &block|
11
- define_entity type_name, *names, &block
12
- end
13
- end
14
-
15
- def processes &block
16
- instance_eval &block
17
- end
18
-
19
- def exchange name, &block
20
- $exchange = ::Rea::MetaType::Exchange.new
21
- $exchange.instance_eval &block
22
- symbol_table[name] = $exchange
23
- end
24
-
25
- def conversion name, &block
26
- $conversion = ::Rea::MetaType::Conversion.new
27
- $conversion.instance_eval &block
28
- symbol_table[name] = $conversion
29
- end
30
-
31
-
32
- def symbol_table
33
- @symbol_table ||= {}.with_indifferent_access
34
- end
35
-
36
- private
37
- def define_entity type, *names, &block
38
- $type_module = "Rea::MetaType::#{type.to_s.camelize}".constantize
39
- $options = names.extract_options!
40
- names.each do |name|
41
- $target_class = name.is_a?(Symbol) ? name.to_s.camelize.constantize : name
42
- $target_class.class_eval do
43
- cattr_accessor :fields
44
- include $type_module
45
- end
46
- $target_class.setup $options unless $options.empty?
47
- $target_class.class_eval &block if block_given?
48
- $name = name.is_a?(Symbol)? name : name.to_s.underscore.to_sym
49
- symbol_table[$name] = $target_class
50
- end
51
- end
52
- end
53
-
54
- def self.included base
55
- end
56
-
57
- def model &block
58
- self.context.instance_eval &block
59
- end
60
-
61
- def context
62
- @context ||= Context.new
63
- end
64
- end
65
- end
@@ -1,18 +0,0 @@
1
- module Rea
2
- module Plugins
3
- module ActiveModel
4
- extend ActiveSupport::Concern
5
-
6
- include ::ActiveModel::Conversion
7
- include ::ActiveModel::Validations
8
- include ::ActiveModel::Serialization
9
- include ::ActiveModel::Serializers::Xml
10
- include ::ActiveModel::Serializers::JSON
11
-
12
- included do
13
- extend ::ActiveModel::Naming
14
- extend ::ActiveModel::Translation
15
- end
16
- end
17
- end
18
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::CategoryMember do
4
- context :associations do
5
- subject { described_class.reflect_on_all_associations.map(&:name) }
6
- it { should include :category }
7
- it { should include :entity }
8
- end
9
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::CategoryType do
4
-
5
- context :class do
6
- subject { described_class }
7
- it { subject.respond_to?(:category_type).should be_true }
8
-
9
- it :could_create_instance do
10
- expect { subject.category_type :category_type_test }.to change {Rea::CategoryType.count}
11
- end
12
-
13
- it :could_yield_block do
14
- expect { |b| subject.category_type :some, &b }.to yield_control
15
- end
16
- end
17
-
18
- context :category do
19
- before :all do
20
- ct = described_class.create! :name=>:type
21
- ct.category :c1, :c2
22
- end
23
-
24
- subject { described_class.first }
25
- its(:categories) { should have(2).items }
26
-
27
- end
28
- end
@@ -1,8 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::GroupType do
4
- context :association do
5
- subject { described_class.reflect_on_all_associations.map(&:name) }
6
- it { should include :groups }
7
- end
8
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::Identifier do
4
- context :validation do
5
- context :correct_setup do
6
-
7
- subject { described_class.new :name=>:name, :id_rule=>'AAABBB#{last_value}'}
8
-
9
- it :stub do end
10
-
11
- after :each do
12
- should be_valid
13
- end
14
-
15
- end
16
-
17
- context :error_setup do
18
- subject { described_class.new :name=>:name, :id_rule=>'AAABBB' }
19
- it :without_name do subject.name=nil end
20
- it :without_id_rule do subject.id_rule = nil end
21
- it :malformed_id_rule do subject.id_rule = 'AAA#{a' end
22
- it :malformed_value_reset_rule do subject.value_reset_rule = 'a > ' end
23
-
24
- after :each do
25
- should_not be_valid
26
- end
27
- end
28
- end
29
-
30
- context :generate do
31
- context :without_value_reset_rule do
32
- subject { described_class.create! :name=>:name, :id_rule=>'AAA#{"%03d" % last_value}' }
33
- it :test_id_value do
34
- subject.generate.should =~ /AAA\d{3}/
35
- subject.reload
36
- subject.last_value.should == 1
37
- end
38
- end
39
-
40
- context :with_value_reset_rule do
41
- subject { described_class.create! :name=>:name, :id_rule=>'AAA', :value_reset_rule=>'true' }
42
- before(:each) { subject.generate }
43
- 5.times do
44
- its(:last_value) { should == 1 }
45
- end
46
- end
47
- end
48
- end
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::AspectType::Classification do
4
- let(:category_type) { Rea::CategoryType.create :name=>:category_type }
5
- let(:category_type_multi) { Rea::CategoryType.create :name=>:category_type_multi }
6
-
7
- before :all do
8
- category_type.category :cate_l1_1, :cate_l1_2
9
- category_type.category :cate_l1_3 do
10
- category :cate_l2_1, :cate_l2_2
11
- end
12
- category_type_multi.category :catem_l1_1, :catem_l1_2
13
- category_type_multi.category :catem_l1_3 do
14
- category :catem_l2_1, :catem_l2_2
15
- end
16
- end
17
-
18
-
19
- context :syntax_symbol_table_classification_aspect do
20
- with_model :resource do
21
- table do |t|
22
- t.string :name
23
- t.decimal :value
24
- t.references :member_type
25
- end
26
- model do
27
- end
28
- end
29
-
30
- before :each do
31
- Rea.model do
32
- entities do
33
- resource :resource do
34
- classification :auto_classification=>false do
35
- member :member_type, :multiple_select=>false do
36
- category :category_type
37
- end
38
- member :member_type_multi, :multiple_select=>true do
39
- category :category_type_multi
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
-
47
-
48
- subject { Rea.context.symbol_table[:resource_classification_aspect] }
49
- it { should_not be_nil }
50
- it { should be_a_kind_of Rea::AspectType::Classification::Aspect }
51
- its(:members) { should have(2).items }
52
- it { subject.member_type_for(:category_type).should == :member_type }
53
- it { subject.member_type_for(:category_type_multi).should == :member_type_multi }
54
-
55
- context :members do
56
- subject { Rea.context.symbol_table[:resource_classification_aspect].members[:member_type_multi] }
57
- its(:multiple_select) { should be_true }
58
- end
59
-
60
- context :model do
61
- let(:category) { ::Rea::Category.find_by_name :cate_l1_1 }
62
-
63
- context :class do
64
- before :each do
65
- Resource.delete_all
66
- 10.times do
67
- Resource.create! :name=>:name, :value=>10, :member_type_id=>category.id
68
- end
69
- end
70
- subject { Resource }
71
- it { subject.by_category(category).size.should == 10 }
72
- it { subject.categories_for(:member_type).size.should == 5 }
73
- end
74
-
75
- context :instance do
76
- subject { Resource.create! :name=>:name, :value=>1, :member_type_id=>category.id }
77
- it { subject.is?(category).should be_true }
78
- it { subject.is_in?(category).should be_true }
79
- end
80
-
81
- context :instance_multi do
82
- let(:resource_multi) do
83
- ids = Rea::CategoryType.find_by_name(:category_type_multi).category_ids
84
- Resource.create! :name=>:name, :value=>1, :member_type_multi_ids=> ids
85
- end
86
-
87
- subject { resource_multi }
88
-
89
- its(:member_type_multi) { should have(5).items }
90
-
91
- end
92
-
93
- end
94
- end
95
-
96
- context :category_type_and_category do
97
-
98
- context :category_type do
99
- subject { category_type }
100
- its(:categories) { should have(5).items }
101
- context :category do
102
- subject{ Rea::Category.find_by_name 'cate_l1_3' }
103
- its(:child_categories) { should have(2).items }
104
- end
105
- end
106
- end
107
- end
@@ -1,75 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::AspectType::DueDate do
4
-
5
- with_model :resource do
6
- table do |t|
7
- t.string :name
8
- t.decimal :value
9
- t.datetime :deadline
10
- end
11
- model do
12
- end
13
- end
14
-
15
- before :each do
16
- Rea.model do
17
- entities do
18
- resource :resource do
19
- due_date do
20
- member :deadline, :editable=>true
21
- member :auto_date, :editable=>false, :activation_rule=>proc{Time.now}
22
- end
23
- end
24
- end
25
- end
26
- end
27
-
28
- context :syntax do
29
- context :aspect do
30
- subject { Rea.context.symbol_table[:resource_due_date_aspect] }
31
- it(:member) { subject.respond_to?(:member).should be_true }
32
- end
33
- context :entity_class do
34
- subject { Resource }
35
- it(:expired_on){ subject.respond_to?(:expired_on).should be_true }
36
- it(:active_on){ subject.respond_to?(:active_on).should be_true }
37
-
38
- context :with_data do
39
- before :each do
40
- subject.delete_all
41
- 10.times do
42
- subject.create :name=>:name1, :value=>1, :deadline=>1.days.ago
43
- subject.create :name=>:name2, :value=>1, :deadline=>1.days.from_now
44
- end
45
- end
46
-
47
- it :active_and_expired do
48
- subject.count.should == 20
49
- subject.active_on(:deadline).size.should == 10
50
- subject.expired_on(:deadline).size.should == 10
51
- end
52
-
53
- end
54
- end
55
- context :entity_instance do
56
- subject { Resource.new }
57
- its(:public_methods) { should include :deadline, :deadline_state, :deadline_expired? }
58
- end
59
- end
60
-
61
- context :model do
62
- context :active do
63
- subject { Resource.new :deadline=> 1.days.from_now }
64
- its(:deadline_state) { should == :active }
65
- its(:deadline_expired?) { should be_false }
66
- end
67
- context :expired do
68
- subject { Resource.new :deadline=> 1.days.ago }
69
- its(:deadline_state) { should == :expired }
70
- its(:deadline_expired?) { should be_true }
71
- end
72
- end
73
- end
74
-
75
-
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::AspectType::Identification do
4
-
5
- def valid_attributes
6
- {:name=>:name, :value=>1}
7
- end
8
-
9
- with_model :resource do
10
- table do |t|
11
- t.string :name
12
- t.decimal :value
13
- t.string :sn
14
- t.string :sn_other
15
- end
16
- model do
17
- end
18
- end
19
-
20
- before :each do
21
- Rea.model do
22
- entities do
23
- resource :resource do
24
- identification do
25
- identifier :sn
26
- identifier :sn_other, :type=>"resource.sn2"
27
- end
28
- end
29
- end
30
- end
31
- end
32
-
33
- context :syntax do
34
- subject { Rea.context.symbol_table[:resource_identification_aspect] }
35
- its(:identifiers) { should have(2).items }
36
- it(:default_type) { subject.identifiers[:sn].type.should == "resource.sn" }
37
- it(:customize_type) { subject.identifiers[:sn_other].type.should == 'resource.sn2'}
38
- end
39
-
40
- context :callback do
41
- before :each do
42
- Rea::Identifier.delete_all
43
- Rea::Identifier.create :name=>"resource.sn", :id_rule=>"RESOURCE_SN"
44
- Rea::Identifier.create :name=>"resource.sn2", :id_rule=>"RESOUCE_SN2"
45
- end
46
-
47
- context :update do
48
- let(:resource) { Resource.create! valid_attributes }
49
- subject { resource }
50
- before(:each) { resource.save }
51
- it { should be_valid }
52
- it { should_not be_sn_changed }
53
- end
54
-
55
- context :create do
56
- subject { Resource.create! valid_attributes }
57
- before(:each) { subject.reload }
58
- its(:sn) { should == "RESOURCE_SN" }
59
- end
60
-
61
- end
62
-
63
- end
64
-
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::AspectType do
4
-
5
- with_model :resource do
6
- table do |t|
7
- t.string :name
8
- t.decimal :value
9
- end
10
- model do
11
- end
12
- end
13
-
14
- before :each do
15
- Rea.model do
16
- entities do
17
- resource :resource
18
- end
19
- end
20
- end
21
-
22
- def valid_attributes
23
- {:name=>:name, :value=>1}
24
- end
25
-
26
- context :syntax do
27
- subject { Resource }
28
-
29
- %W{classification identification description due_date}.each do |method|
30
- context "#{method}_context" do
31
- before(:each) do
32
- subject.send method, :name
33
- end
34
- it("respond_to? #{method}"){ subject.respond_to?(method).should be_true }
35
- it("block called #{method}") do
36
- expect { |b| subject.send(method,:"#{method}_aspect", &b) }.to yield_control
37
- end
38
- its("ancestors") { should include "Rea::AspectType::#{method.camelize}".constantize }
39
- its("#{method}_aspect") { should be_a_kind_of "Rea::AspectType::#{method.camelize}::Aspect".constantize }
40
- end
41
- end
42
- end
43
-
44
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::MetaType::Agent do
4
-
5
- context :active_record_resource_define do
6
- with_model :agent do
7
- table do |t|
8
- t.string :name
9
- end
10
- end
11
-
12
- before(:each) do
13
- Rea.model do
14
- entities do
15
- agent :agent
16
- end
17
- end
18
- end
19
-
20
- subject { Agent.new :name=>:name }
21
- it { should be_valid }
22
- it :name_not_nil do
23
- subject.name = nil
24
- should_not be_valid
25
- end
26
-
27
- end
28
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::MetaType::Commitment do
4
-
5
- with_model :commitment do
6
- table do |t|
7
- t.references :provider
8
- t.references :resource
9
- t.decimal :amount
10
- t.boolean :fulfilled
11
- end
12
- model do
13
- end
14
- end
15
-
16
- before(:each) do
17
- Rea.model do
18
- entities do
19
- commitment :commitment, :type=>:increment do
20
- event_creator do
21
- raise :callback
22
- end
23
- end
24
- end
25
-
26
- end
27
- end
28
-
29
- context :syntax do
30
- subject { Rea.context.symbol_table[:commitment] }
31
- its(:ancestors) { should include Rea::MetaType::Commitment }
32
- its(:event_handler) {should_not be_nil }
33
- end
34
-
35
- context :model do
36
- subject { Commitment.new :amount=>1 }
37
- it {
38
- expect do |b|
39
- Commitment.event_creator &b
40
- subject.fulfilled = true
41
- subject.save
42
- end.to yield_control
43
- }
44
- end
45
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rea::MetaType::Contract do
4
-
5
- with_model :contract do
6
- table do |t|
7
- end
8
- model do
9
- end
10
- end
11
- with_model :agent do
12
-
13
- end
14
- with_model :commitment do
15
- table do
16
- end
17
- model do
18
- end
19
- end
20
-
21
- before(:each) do
22
- Rea.model do
23
- entities do
24
- agent :agent
25
- commitment :commitment
26
- contract :contract do
27
- clause :commitment
28
- party :buyer, Agent
29
- party :seller, :agent
30
- end
31
- end
32
- end
33
- end
34
-
35
- context :syntax do
36
- subject { Rea.context.symbol_table[:contract] }
37
- it { should_not be_nil }
38
- its(:clauses) { should include Commitment }
39
- its(:reflect_on_all_associations) { should have(3).items }
40
- end
41
-
42
- end