mdd 3.0.2 → 3.0.3
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/app/helpers/mdwa_helper.rb +2 -1
- data/lib/generators/mdwa/association/association_generator.rb +1 -1
- data/lib/generators/mdwa/association/templates/migrate/many_to_many.rb +1 -1
- data/lib/generators/mdwa/association/templates/migrate/one_field.rb +2 -1
- data/lib/generators/mdwa/code/code_generator.rb +54 -22
- data/lib/generators/mdwa/code/templates/migration.rb +2 -1
- data/lib/generators/mdwa/entity/entity_generator.rb +1 -2
- data/lib/generators/mdwa/entity/templates/entity.rb +2 -1
- data/lib/generators/mdwa/from_requirements/from_requirements_generator.rb +56 -0
- data/lib/generators/mdwa/process/USAGE +4 -0
- data/lib/generators/mdwa/process/process_generator.rb +24 -0
- data/lib/generators/mdwa/process/templates/process.rb +49 -0
- data/lib/generators/mdwa/requirement/USAGE +4 -0
- data/lib/generators/mdwa/requirement/requirement_generator.rb +24 -0
- data/lib/generators/mdwa/requirement/templates/requirement.rb +21 -0
- data/lib/generators/mdwa/sandbox/sandbox_generator.rb +1 -1
- data/lib/generators/mdwa/sandbox/templates/app/assets/stylesheets/mdwa/template/backend.css.erb +2 -2
- data/lib/generators/mdwa/sandbox/templates/app/controllers/a/backend_controller.rb +2 -1
- data/lib/generators/mdwa/sandbox/templates/app/controllers/a/users/sessions_controller.rb +1 -1
- data/lib/generators/mdwa/sandbox/templates/app/controllers/public_controller.rb +1 -0
- data/lib/generators/mdwa/sandbox/templates/config/initializers/devise.rb +1 -0
- data/lib/generators/mdwa/sandbox/templates/config/initializers/mdwa_layout.rb +2 -1
- data/lib/generators/mdwa/sandbox/templates/config/locales/mdwa.en.yml +1 -1
- data/lib/generators/mdwa/sandbox/templates/db/migrate/devise_create_users.rb +1 -1
- data/lib/generators/mdwa/sandbox/templates/db/seeds.rb +1 -1
- data/lib/generators/mdwa/sandbox/templates/db/seeds/site.rb +1 -1
- data/lib/generators/mdwa/scaffold/scaffold_generator.rb +10 -3
- data/lib/generators/mdwa/scaffold/templates/controllers/ajax_controller.rb +2 -1
- data/lib/generators/mdwa/scaffold/templates/controllers/controller.rb +2 -1
- data/lib/generators/mdwa/scaffold/templates/db_migrate/migrate.rb +2 -1
- data/lib/generators/mdwa/scaffold/templates/models/model.rb +2 -1
- data/lib/generators/mdwa/scaffold/templates/models/module.rb +2 -1
- data/lib/generators/mdwa/user/templates/user.rb +12 -0
- data/lib/generators/mdwa/user/user_generator.rb +13 -104
- data/lib/generators/mdwa/{user → user_scaffold}/USAGE +1 -1
- data/lib/generators/mdwa/{user → user_scaffold}/templates/controllers/ajax_controller.rb +2 -1
- data/lib/generators/mdwa/{user → user_scaffold}/templates/controllers/controller.rb +2 -1
- data/lib/generators/mdwa/{user → user_scaffold}/templates/migrate.rb +2 -1
- data/lib/generators/mdwa/{user → user_scaffold}/templates/views/update.js.erb +0 -0
- data/lib/generators/mdwa/user_scaffold/user_scaffold_generator.rb +139 -0
- data/lib/mdd.rb +1 -1
- data/lib/mdwa.rb +1 -1
- data/lib/mdwa/all.rb +1 -1
- data/lib/mdwa/dsl.rb +17 -4
- data/lib/mdwa/dsl/action.rb +78 -0
- data/lib/mdwa/dsl/entities.rb +4 -4
- data/lib/mdwa/dsl/entity.rb +59 -23
- data/lib/mdwa/dsl/entity_actions.rb +73 -0
- data/lib/mdwa/dsl/entity_association.rb +1 -1
- data/lib/mdwa/dsl/entity_attribute.rb +1 -1
- data/lib/mdwa/dsl/entity_specification.rb +22 -0
- data/lib/mdwa/dsl/process.rb +53 -0
- data/lib/mdwa/dsl/process_detail.rb +57 -0
- data/lib/mdwa/dsl/process_detail_next_action.rb +16 -0
- data/lib/mdwa/dsl/requirement.rb +23 -0
- data/lib/mdwa/dsl/requirements.rb +57 -0
- data/lib/mdwa/dsl/user.rb +34 -0
- data/lib/mdwa/dsl/users.rb +57 -0
- data/lib/mdwa/dsl/workflow.rb +57 -0
- data/lib/mdwa/generators.rb +1 -1
- data/lib/mdwa/generators/model.rb +3 -1
- data/lib/mdwa/generators/model_association.rb +4 -1
- data/lib/mdwa/generators/model_attribute.rb +2 -1
- data/lib/mdwa/layout.rb +1 -1
- data/lib/mdwa/layout/base.rb +1 -1
- data/lib/mdwa/layout/helper.rb +1 -1
- data/lib/mdwa/version.rb +1 -1
- data/test/entity_actions_test.rb +101 -0
- data/test/entity_specifications_test.rb +37 -0
- data/test/entity_test.rb +1 -1
- data/test/layout_test.rb +1 -1
- data/test/process_test.rb +86 -0
- data/test/requirements_test.rb +44 -0
- data/test/users_test.rb +55 -0
- metadata +37 -10
- data/lib/mdwa/dsl/generator.rb +0 -10
- data/test/generators_test.rb +0 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'ostruct'
|
3
|
+
module MDWA
|
4
|
+
module DSL
|
5
|
+
|
6
|
+
class ProcessDetail
|
7
|
+
attr_accessor :process, :description, :alias, :user_roles, :detail_action, :next_actions
|
8
|
+
|
9
|
+
def initialize(process, description)
|
10
|
+
self.process = process
|
11
|
+
self.description = description
|
12
|
+
|
13
|
+
self.user_roles = []
|
14
|
+
self.next_actions = []
|
15
|
+
self.detail_action = OpenStruct.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# Unique alias for detailing
|
19
|
+
# Default: Detail name underscored
|
20
|
+
def alias
|
21
|
+
@alias ||= self.description.gsub(' ', '_').underscore
|
22
|
+
end
|
23
|
+
|
24
|
+
# Refered action
|
25
|
+
# Params:
|
26
|
+
# => :entity
|
27
|
+
# => :action
|
28
|
+
def action(entity, action)
|
29
|
+
self.detail_action.entity = entity
|
30
|
+
self.detail_action.action = action
|
31
|
+
end
|
32
|
+
|
33
|
+
# Possible next action
|
34
|
+
# Params:
|
35
|
+
# => :alias
|
36
|
+
# => :entity
|
37
|
+
# => :action
|
38
|
+
# => :method
|
39
|
+
# => :request
|
40
|
+
# => :redirect => boolean
|
41
|
+
# => :render => boolean
|
42
|
+
# => :when - situation when it might occur
|
43
|
+
def next_action(detail_alias, options = {})
|
44
|
+
next_action = ProcessDetailNextAction.new(detail_alias)
|
45
|
+
next_action.method = options[:method] || :get
|
46
|
+
next_action.request = options[:request] || :html
|
47
|
+
next_action.redirect = options[:redirect] || false
|
48
|
+
next_action.render = options[:render] || false
|
49
|
+
next_action.when = options[:when]
|
50
|
+
|
51
|
+
next_actions << next_action
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end # dsl
|
57
|
+
end # mdwa
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module MDWA
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
class ProcessDetailNextAction
|
6
|
+
|
7
|
+
attr_accessor :alias, :method, :request, :redirect, :render, :when
|
8
|
+
|
9
|
+
def initialize(next_action_alias)
|
10
|
+
self.alias = next_action_alias
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end # dsl
|
16
|
+
end # mdwa
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module MDWA
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
class Requirement
|
6
|
+
|
7
|
+
attr_accessor :summary, :description, :alias, :users, :entities
|
8
|
+
|
9
|
+
def initialize(summary = nil)
|
10
|
+
self.summary = summary
|
11
|
+
|
12
|
+
self.users = []
|
13
|
+
self.entities = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def alias
|
17
|
+
@alias ||= self.summary.gsub(' ', '_').underscore
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end # dsl
|
23
|
+
end # mdwa
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module MDWA
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
# singleton class
|
6
|
+
class Requirements
|
7
|
+
|
8
|
+
attr_accessor :nodes
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@nodes ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.instance
|
15
|
+
@__instance__ ||= new
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Register a new requirement in the list.
|
20
|
+
#
|
21
|
+
def register( summary = nil )
|
22
|
+
# retrive or initialize a entity
|
23
|
+
req = Requirement.new( summary )
|
24
|
+
yield(req) if block_given?
|
25
|
+
add_node(req) # add to the list
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Add note to the entity list
|
30
|
+
# Prevents entity duplication
|
31
|
+
#
|
32
|
+
def add_node(node)
|
33
|
+
@nodes[node.alias] = node
|
34
|
+
end
|
35
|
+
|
36
|
+
def element(e)
|
37
|
+
@nodes[e]
|
38
|
+
end
|
39
|
+
|
40
|
+
def all
|
41
|
+
@nodes.values
|
42
|
+
end
|
43
|
+
|
44
|
+
end # class
|
45
|
+
|
46
|
+
# return the requirements instance
|
47
|
+
def self.requirements
|
48
|
+
Requirements.instance
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.requirement(name)
|
52
|
+
self.requirements.element(name)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end # dsl
|
57
|
+
end # mdd
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module MDWA
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
class User
|
6
|
+
|
7
|
+
attr_accessor :name, :description, :user_roles
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
self.name = name.camelize
|
11
|
+
|
12
|
+
self.clear_user_roles
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_roles
|
16
|
+
@user_roles.uniq
|
17
|
+
end
|
18
|
+
|
19
|
+
def user_roles=(value)
|
20
|
+
if value.is_a? Array
|
21
|
+
@user_roles = @user_roles | value
|
22
|
+
else
|
23
|
+
@user_roles = @user_roles | [value]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def clear_user_roles
|
28
|
+
@user_roles = [self.name]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module MDWA
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
# singleton class
|
6
|
+
class Users
|
7
|
+
|
8
|
+
attr_accessor :nodes
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@nodes ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.instance
|
15
|
+
@__instance__ ||= new
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Register a new user in the list.
|
20
|
+
#
|
21
|
+
def register( name )
|
22
|
+
# retrive or initialize a entity
|
23
|
+
user = element(name) || User.new( name )
|
24
|
+
yield(user) if block_given?
|
25
|
+
add_node user # add to the list
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Add note to the entity list
|
30
|
+
# Prevents entity duplication
|
31
|
+
#
|
32
|
+
def add_node(node)
|
33
|
+
@nodes[node.name] = node
|
34
|
+
end
|
35
|
+
|
36
|
+
def element(e)
|
37
|
+
@nodes[e]
|
38
|
+
end
|
39
|
+
|
40
|
+
def all
|
41
|
+
@nodes.values
|
42
|
+
end
|
43
|
+
|
44
|
+
end # class entitites
|
45
|
+
|
46
|
+
# return the entities instance
|
47
|
+
def self.users
|
48
|
+
Users.instance
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.user(name)
|
52
|
+
self.users.element(name)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end # dsl
|
57
|
+
end # mdd
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module MDWA
|
3
|
+
module DSL
|
4
|
+
|
5
|
+
# singleton class
|
6
|
+
class Workflow
|
7
|
+
|
8
|
+
attr_accessor :nodes
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@nodes ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.instance
|
15
|
+
@__instance__ ||= new
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Register a new user in the list.
|
20
|
+
#
|
21
|
+
def register( name )
|
22
|
+
# retrive or initialize a entity
|
23
|
+
process = element(name) || Process.new( name )
|
24
|
+
yield(process) if block_given?
|
25
|
+
add_node process # add to the list
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Add note to the entity list
|
30
|
+
# Prevents entity duplication
|
31
|
+
#
|
32
|
+
def add_node(node)
|
33
|
+
@nodes[node.alias] = node
|
34
|
+
end
|
35
|
+
|
36
|
+
def element(e)
|
37
|
+
@nodes[e]
|
38
|
+
end
|
39
|
+
|
40
|
+
def all
|
41
|
+
@nodes.values
|
42
|
+
end
|
43
|
+
|
44
|
+
end # class entitites
|
45
|
+
|
46
|
+
# return the entities instance
|
47
|
+
def self.workflow
|
48
|
+
Workflow.instance
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.process(name)
|
52
|
+
self.workflow.element(name)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end # dsl
|
57
|
+
end # mdd
|
data/lib/mdwa/generators.rb
CHANGED
data/lib/mdwa/layout.rb
CHANGED
data/lib/mdwa/layout/base.rb
CHANGED
data/lib/mdwa/layout/helper.rb
CHANGED
data/lib/mdwa/version.rb
CHANGED
@@ -0,0 +1,101 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'mdwa/dsl'
|
3
|
+
|
4
|
+
require 'minitest/spec'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
|
7
|
+
describe MDWA::DSL::EntityActions do
|
8
|
+
|
9
|
+
before do
|
10
|
+
# create product entity
|
11
|
+
MDWA::DSL.entities.register "Product" do |e|
|
12
|
+
e.resource = true
|
13
|
+
e.ajax = true
|
14
|
+
|
15
|
+
e.member_action :publish, :get, :html
|
16
|
+
e.collection_action :export, :post, [:csv, :xml]
|
17
|
+
e.collection_action :report, :get, [:ajax]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create action correctly" do
|
22
|
+
action = MDWA::DSL::Action.new :publish, :member, :method => :get, :request_type => [:html, :ajax_js]
|
23
|
+
action.name.must_equal :publish
|
24
|
+
action.member?.must_equal true
|
25
|
+
action.method.must_equal :get
|
26
|
+
action.resource?.must_equal false
|
27
|
+
action.request_type.must_equal [:html, :ajax_js]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should store resource actions correctly" do
|
31
|
+
product = MDWA::DSL.entity('Product')
|
32
|
+
product.actions.actions.count.must_equal 10
|
33
|
+
product.actions.actions[:index].must_be_instance_of MDWA::DSL::Action
|
34
|
+
product.actions.actions[:index].collection?.must_equal true
|
35
|
+
product.actions.actions[:index].member?.must_equal false
|
36
|
+
product.actions.actions[:index].name.must_equal :index
|
37
|
+
|
38
|
+
product.actions.actions[:new].must_be_instance_of MDWA::DSL::Action
|
39
|
+
product.actions.actions[:new].collection?.must_equal true
|
40
|
+
product.actions.actions[:new].name.must_equal :new
|
41
|
+
|
42
|
+
product.actions.actions[:edit].must_be_instance_of MDWA::DSL::Action
|
43
|
+
product.actions.actions[:edit].collection?.must_equal false
|
44
|
+
product.actions.actions[:edit].member?.must_equal true
|
45
|
+
product.actions.actions[:edit].name.must_equal :edit
|
46
|
+
|
47
|
+
product.actions.actions[:show].must_be_instance_of MDWA::DSL::Action
|
48
|
+
product.actions.actions[:show].member?.must_equal true
|
49
|
+
product.actions.actions[:show].name.must_equal :show
|
50
|
+
|
51
|
+
product.actions.actions[:create].must_be_instance_of MDWA::DSL::Action
|
52
|
+
product.actions.actions[:create].collection?.must_equal true
|
53
|
+
product.actions.actions[:create].name.must_equal :create
|
54
|
+
|
55
|
+
product.actions.actions[:update].must_be_instance_of MDWA::DSL::Action
|
56
|
+
product.actions.actions[:update].member?.must_equal true
|
57
|
+
product.actions.actions[:update].name.must_equal :update
|
58
|
+
|
59
|
+
product.actions.actions[:delete].must_be_instance_of MDWA::DSL::Action
|
60
|
+
product.actions.actions[:delete].member?.must_equal true
|
61
|
+
|
62
|
+
product.actions.actions[:no_ecsiste].must_equal nil
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should work well with non-resourceful actions" do
|
66
|
+
product = MDWA::DSL.entity('Product')
|
67
|
+
product.actions.member_actions.count.must_equal 1
|
68
|
+
product.actions.actions[:publish].name.must_equal :publish
|
69
|
+
product.actions.actions[:publish].method.must_equal :get
|
70
|
+
product.actions.actions[:publish].request_type.must_equal [:html]
|
71
|
+
product.actions.actions[:publish].resource?.must_equal false
|
72
|
+
|
73
|
+
product.actions.collection_actions.count.must_equal 2
|
74
|
+
product.actions.actions[:export].name.must_equal :export
|
75
|
+
product.actions.actions[:export].method.must_equal :post
|
76
|
+
product.actions.actions[:export].request_type.must_equal [:csv, :xml]
|
77
|
+
product.actions.actions[:export].resource?.must_equal false
|
78
|
+
|
79
|
+
product.actions.actions[:report].name.must_equal :report
|
80
|
+
product.actions.actions[:report].method.must_equal :get
|
81
|
+
product.actions.actions[:report].request_type.must_equal [:ajax]
|
82
|
+
product.actions.actions[:report].resource?.must_equal false
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not generate actions for non-resourceful entities" do
|
86
|
+
|
87
|
+
MDWA::DSL.entities.register 'Reports' do |e|
|
88
|
+
e.resource = false
|
89
|
+
end
|
90
|
+
|
91
|
+
reports = MDWA::DSL.entity('Reports')
|
92
|
+
reports.actions.actions.count.must_equal 0
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should generate correct code" do
|
97
|
+
product = MDWA::DSL.entity('Product')
|
98
|
+
puts product.actions.generate_routes
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|