mdd 3.0.0 → 3.0.1
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/lib/generators/mdwa/association/association_generator.rb +11 -10
- data/lib/generators/mdwa/association/templates/migrate/many_to_many.rb +3 -3
- data/lib/generators/mdwa/code/USAGE +5 -0
- data/lib/generators/mdwa/code/code_generator.rb +166 -0
- data/lib/generators/mdwa/code/templates/migration.rb +15 -0
- data/lib/generators/mdwa/entity/USAGE +5 -0
- data/lib/generators/mdwa/entity/entity_generator.rb +25 -0
- data/lib/generators/mdwa/entity/templates/entity.rb +50 -0
- data/lib/generators/mdwa/sandbox/sandbox_generator.rb +3 -1
- data/lib/generators/mdwa/sandbox/templates/app/controllers/a/home_controller.rb +4 -0
- data/lib/generators/mdwa/sandbox/templates/app/views/a/administrators/_form.html.erb +6 -38
- data/lib/generators/mdwa/sandbox/templates/app/views/a/administrators/_form_fields.html.erb +25 -0
- data/lib/generators/mdwa/sandbox/templates/db/seeds/site.rb +2 -1
- data/lib/generators/mdwa/scaffold/scaffold_generator.rb +5 -3
- data/lib/generators/mdwa/scaffold/templates/views/_list.html.erb +1 -1
- data/lib/generators/mdwa/user/USAGE +3 -0
- data/lib/generators/mdwa/user/templates/controllers/ajax_controller.rb +78 -0
- data/lib/generators/mdwa/user/templates/controllers/controller.rb +77 -0
- data/lib/generators/mdwa/user/templates/migrate.rb +15 -0
- data/lib/generators/mdwa/user/templates/model.rb +11 -0
- data/lib/generators/mdwa/user/templates/views/update.js.erb +12 -0
- data/lib/generators/mdwa/user/user_generator.rb +113 -0
- data/lib/mdwa/dsl.rb +7 -1
- data/lib/mdwa/dsl/entities.rb +14 -2
- data/lib/mdwa/dsl/entity.rb +94 -9
- data/lib/mdwa/dsl/entity_association.rb +59 -0
- data/lib/mdwa/dsl/entity_attribute.rb +46 -0
- data/lib/mdwa/dsl/generator.rb +10 -0
- data/lib/mdwa/generators/model.rb +13 -4
- data/lib/mdwa/generators/model_association.rb +1 -1
- data/lib/mdwa/generators/model_attribute.rb +10 -9
- data/lib/mdwa/version.rb +1 -1
- data/mdd.gemspec +1 -0
- data/test/entity_test.rb +188 -13
- metadata +35 -2
@@ -0,0 +1,25 @@
|
|
1
|
+
<div class="yui3-u-1-2">
|
2
|
+
<div class="field">
|
3
|
+
<%= f.label :name %>
|
4
|
+
<%= f.text_field :name %>
|
5
|
+
</div>
|
6
|
+
<div class="field">
|
7
|
+
<%= f.label :email %>
|
8
|
+
<%= f.text_field :email %>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="yui3-u-1-2">
|
13
|
+
<% unless @administrator.new_record? %>
|
14
|
+
<p class="description"><%= raw t('administrators.edit_form_password_text') %></p>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<div class="field">
|
18
|
+
<%= f.label :password, t('administrators.edit_form_password') %>
|
19
|
+
<%= f.password_field :password %>
|
20
|
+
</div>
|
21
|
+
<div class="field">
|
22
|
+
<%= f.label :password_confirmation, t('administrators.edit_form_password_confirmation') %>
|
23
|
+
<%= f.password_field :password_confirmation %>
|
24
|
+
</div>
|
25
|
+
</div>
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
+
Permission.create( :name => "SuperAdmin" ) if Permission.find_by_name("SuperAdmin").nil?
|
3
|
+
|
2
4
|
if Administrator.count.zero?
|
3
|
-
Permission.create( :name => "SuperAdmin" ) if Permission.find_by_name("SuperAdmin").nil?
|
4
5
|
Administrator.create :name => "Administrator", :email => 'admin@admin.com', :password => 'admin123', :password_confirmation => 'admin123'
|
5
6
|
end
|
@@ -18,7 +18,9 @@ module Mdwa
|
|
18
18
|
class_option :model, :desc => 'Use if model is different than the scaffold name. Format: "[namespace]/Model"', :type => :string
|
19
19
|
class_option :ajax, :desc => 'Generates modal forms and AJAX submits.', :type => :boolean, :default => false
|
20
20
|
class_option :skip_migrations, :desc => 'Skips the generation of a new migration.', :type => :boolean, :default => false
|
21
|
+
class_option :skip_rake_migrate, :desc => 'Skips running rake db:migrate', :type => :boolean, :default => false
|
21
22
|
class_option :skip_timestamp, :desc => 'Skip timestamp generator on migration files.', :type => :boolean, :default => false
|
23
|
+
class_option :skip_questions, :desc => 'Answer no for all questions by default.', :type => :boolean, :default => false
|
22
24
|
class_option :skip_interface, :desc => 'Cretes only models, migrations and associations.', :type => :boolean, :default => false
|
23
25
|
class_option :only_interface, :desc => 'Skips models, associations and migrations.', :type => :boolean, :default => false
|
24
26
|
|
@@ -120,14 +122,14 @@ module Mdwa
|
|
120
122
|
def associations
|
121
123
|
unless options.only_interface
|
122
124
|
@model.attributes.select{ |a| a.references? }.each do |attr|
|
123
|
-
generate "mdwa:association #{@model.raw} #{attr.reference_type} #{attr.type.raw} #{'--skip_migrations' if options.skip_migrations} #{'--force' if options.force} --
|
125
|
+
generate "mdwa:association #{@model.raw} #{attr.reference_type} #{attr.type.raw} #{'--skip_migrations' if options.skip_migrations} #{'--force' if options.force} #{'--ask' unless options.skip_questions} --skip_rake_migrate"
|
124
126
|
end
|
125
127
|
end
|
126
128
|
end
|
127
129
|
|
128
130
|
def run_rake_db_migrate
|
129
|
-
|
130
|
-
rake('db:migrate') if yes? 'Run rake db:migrate?'
|
131
|
+
if !options.skip_rake_migrate and !options.skip_migrations and !options.only_interface
|
132
|
+
rake('db:migrate') if !options.skip_questions and yes? 'Run rake db:migrate?'
|
131
133
|
end
|
132
134
|
end
|
133
135
|
|
@@ -21,7 +21,7 @@
|
|
21
21
|
<%%= <%= @model.singular_name %>.<%= attr.name %> %>
|
22
22
|
<%- elsif attr.belongs_to? || attr.nested_one? -%>
|
23
23
|
<%%= <%= @model.singular_name %>.<%= attr.type.singular_name %>.<%= attr.reference %> %>
|
24
|
-
<%- elsif attr.has_many? or attr.nested_many? -%>
|
24
|
+
<%- elsif attr.has_many? or attr.has_and_belongs_to_many? or attr.nested_many? -%>
|
25
25
|
<ul>
|
26
26
|
<%% <%= @model.singular_name %>.<%= attr.type.plural_name %>.each do |<%= attr.type.singular_name %>| %>
|
27
27
|
<li><%%= <%= attr.type.singular_name %>.<%= attr.reference %> %> </li>
|
@@ -0,0 +1,78 @@
|
|
1
|
+
class <%= @model.controller_name %>Controller < <%= @inherit_controller || 'ApplicationController' %>
|
2
|
+
|
3
|
+
load_and_authorize_resource :class => "<%= @model.klass %>"
|
4
|
+
|
5
|
+
def index
|
6
|
+
@<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => params[:page]
|
7
|
+
|
8
|
+
respond_to do |format|
|
9
|
+
format.html
|
10
|
+
format.js
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def show
|
16
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
17
|
+
render :layout => false
|
18
|
+
end
|
19
|
+
|
20
|
+
def new
|
21
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new
|
22
|
+
<%- @model.attributes.select {|a| a.nested_one?}.each do |attr| -%>
|
23
|
+
@<%= @model.singular_name %>.<%= attr.type.singular_name %> = <%= attr.type.klass %>.new
|
24
|
+
<%- end -%>
|
25
|
+
render :layout => false
|
26
|
+
end
|
27
|
+
|
28
|
+
def edit
|
29
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
30
|
+
render :layout => false if params[:static_html].blank? or params[:static_html] != '1'
|
31
|
+
end
|
32
|
+
|
33
|
+
def create
|
34
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new(params[:<%= @model.to_params %>])
|
35
|
+
@system_notice = t('<%= @model.plural_name %>.create_success') if @<%= @model.singular_name %>.save
|
36
|
+
# loads all <%= @model.plural_name %> to display in the list
|
37
|
+
load_list
|
38
|
+
|
39
|
+
respond_to do |format|
|
40
|
+
format.js
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def update
|
45
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
46
|
+
# if password is blank, delete from params
|
47
|
+
if params[:<%= @model.object_name %>][:password].blank?
|
48
|
+
params[:<%= @model.object_name %>].delete :password
|
49
|
+
params[:<%= @model.object_name %>].delete :password_confirmation
|
50
|
+
end
|
51
|
+
@system_notice = t('<%= @model.plural_name %>.update_success') if @<%= @model.singular_name %>.update_attributes(params[:<%= @model.to_params %>])
|
52
|
+
|
53
|
+
# loads all <%= @model.plural_name %> to display in the list
|
54
|
+
load_list
|
55
|
+
|
56
|
+
respond_to do |format|
|
57
|
+
format.js
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def destroy
|
62
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
63
|
+
@system_notice = t('<%= @model.plural_name %>.destroy_success') if @<%= @model.singular_name %>.destroy
|
64
|
+
|
65
|
+
# loads all <%= @model.plural_name %> to display in the list
|
66
|
+
load_list
|
67
|
+
|
68
|
+
respond_to do |format|
|
69
|
+
format.js
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def load_list
|
75
|
+
@<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => 1
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class <%= @model.controller_name %>Controller < <%= @inherit_controller || 'ApplicationController' %>
|
2
|
+
|
3
|
+
load_and_authorize_resource :class => "<%= @model.klass %>"
|
4
|
+
|
5
|
+
def index
|
6
|
+
@<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => params[:page]
|
7
|
+
|
8
|
+
respond_to do |format|
|
9
|
+
format.html
|
10
|
+
format.js
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def show
|
16
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def new
|
24
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new
|
25
|
+
<%- @model.attributes.select {|a| a.nested_one?}.each do |attr| -%>
|
26
|
+
@<%= @model.singular_name %>.<%= attr.type.singular_name %> = <%= attr.type.klass %>.new
|
27
|
+
<%- end -%>
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def edit
|
35
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
36
|
+
end
|
37
|
+
|
38
|
+
def create
|
39
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new(params[:<%= @model.object_name %>])
|
40
|
+
|
41
|
+
respond_to do |format|
|
42
|
+
if @<%= @model.singular_name %>.save
|
43
|
+
format.html { redirect_to <%= @model.object_name.pluralize %>_path, notice: t('<%= @model.plural_name %>.create_success') }
|
44
|
+
else
|
45
|
+
format.html { render action: "new" }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def update
|
51
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
52
|
+
# if password is blank, delete from params
|
53
|
+
if params[:<%= @model.object_name %>][:password].blank?
|
54
|
+
params[:<%= @model.object_name %>].delete :password
|
55
|
+
params[:<%= @model.object_name %>].delete :password_confirmation
|
56
|
+
end
|
57
|
+
|
58
|
+
respond_to do |format|
|
59
|
+
if @<%= @model.singular_name %>.update_attributes(params[:<%= @model.object_name %>])
|
60
|
+
format.html { redirect_to <%= @model.object_name.pluralize %>_path, notice: t('<%= @model.plural_name %>.update_success') }
|
61
|
+
else
|
62
|
+
format.html { render action: "edit" }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def destroy
|
68
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
69
|
+
|
70
|
+
@<%= @model.singular_name %>.destroy
|
71
|
+
|
72
|
+
respond_to do |format|
|
73
|
+
format.html { redirect_to <%= @model.object_name.pluralize %>_path, notice: t('<%= @model.plural_name %>.destroy_success') }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Add<%= @model.attributes.collect{|a| a.name.camelize}.join('') %>ToUsers < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
<%- @model.simple_attributes.each do |attr| -%>
|
5
|
+
add_column :users, :<%= attr.name %>, :<%= attr.migration_field %>
|
6
|
+
<%- end -%>
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
<%- @model.simple_attributes.each do |attr| -%>
|
11
|
+
remove_column :users, :<%= attr.name %>
|
12
|
+
<%- end -%>
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= @model.klass %> < User
|
2
|
+
|
3
|
+
attr_accessible <%= @model.simple_attributes.collect {|a| ":" + a.name }.join(', ') %>
|
4
|
+
|
5
|
+
after_create :create_<%= @model.singular_name %>_permission
|
6
|
+
|
7
|
+
def create_<%= @model.singular_name %>_permission
|
8
|
+
self.permissions.push Permission.find_by_name("<%= @model.singular_name %>")
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%% if @<%= @model.singular_name %>.errors.any? %>
|
2
|
+
$("#mdwa_error").html("<%%= escape_javascript( render '/template/mdwa/crud_error', :object => @<%= @model.singular_name %> )%>");
|
3
|
+
<%% else %>
|
4
|
+
if( $('#<%= @model.plural_name %>_list').length > 0 ) {
|
5
|
+
$.fancybox.close(true);
|
6
|
+
$("#<%= @model.plural_name %>_list").html("<%%= escape_javascript( render '<%= @model.plural_name %>' )%>");
|
7
|
+
}
|
8
|
+
else if( $("#edit_<%= @model.plural_name %>").length > 0 ) {
|
9
|
+
$("#edit_<%= @model.plural_name %> .inside").html("<%%= escape_javascript( render 'form' )%>");
|
10
|
+
}
|
11
|
+
$('body').append("<%%= escape_javascript( render '/template/mdwa/notice', :notice => @system_notice )%>");
|
12
|
+
<%% end %>
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
require 'mdwa/generators'
|
3
|
+
|
4
|
+
module Mdwa
|
5
|
+
|
6
|
+
module Generators
|
7
|
+
|
8
|
+
class UserGenerator < Rails::Generators::Base
|
9
|
+
include Rails::Generators::Migration
|
10
|
+
|
11
|
+
source_root File.expand_path('../templates', __FILE__)
|
12
|
+
|
13
|
+
attr_accessor :model, :specific_model
|
14
|
+
|
15
|
+
argument :scaffold_name, :type => :string, :banner => "[namespace]/Model"
|
16
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
17
|
+
|
18
|
+
class_option :model, :desc => 'Use if model is different than the scaffold name. Format: "[namespace]/Model"', :type => :string
|
19
|
+
class_option :ajax, :desc => 'Generates modal forms and AJAX submits.', :type => :boolean, :default => false
|
20
|
+
class_option :skip_rake_migrate, :desc => 'Skips running rake db:migrate', :type => :boolean, :default => false
|
21
|
+
class_option :skip_timestamp, :desc => 'Skip timestamp generator on migration files.', :type => :boolean, :default => false
|
22
|
+
class_option :skip_questions, :desc => 'Answer no for all questions by default.', :type => :boolean, :default => false
|
23
|
+
class_option :skip_interface, :desc => 'Cretes only models, migrations and associations.', :type => :boolean, :default => false
|
24
|
+
class_option :only_interface, :desc => 'Skips models, associations and migrations.', :type => :boolean, :default => false
|
25
|
+
|
26
|
+
def initialize(*args, &block)
|
27
|
+
|
28
|
+
super
|
29
|
+
|
30
|
+
@model = MDWA::Generators::Model.new( scaffold_name )
|
31
|
+
|
32
|
+
# model_name is not valid
|
33
|
+
print_usage unless @model.valid?
|
34
|
+
|
35
|
+
# verifies specific model name
|
36
|
+
@specific_model = MDWA::Generators::Model.new( options.model ) unless options.model.blank?
|
37
|
+
if !@specific_model.nil?
|
38
|
+
if !@specific_model.valid?
|
39
|
+
print_usage
|
40
|
+
else
|
41
|
+
@model.specific_model_name = @specific_model.raw
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
require_all "#{Rails.root}/app/models/user.rb"
|
46
|
+
@predefined_fields = User.column_names
|
47
|
+
@predefined_fields << 'password'
|
48
|
+
@predefined_fields << 'password_confirmation'
|
49
|
+
|
50
|
+
# sets the model attributes
|
51
|
+
attributes.each do |attribute|
|
52
|
+
@model.add_attribute MDWA::Generators::ModelAttribute.new( attribute ) unless User.accessible_attributes.to_a.include?( attribute.split(':').first )
|
53
|
+
end
|
54
|
+
|
55
|
+
generate "mdwa:scaffold #{scaffold_name} name:string email:string password:password password_confirmation:password #{attributes.join(' ')} #{'--force' if options.force} #{'--ajax' if options.ajax} #{"model=#{options.model}" if options.model} #{'--skip_interface' if options.skip_interface} #{'--only_interface' if options.only_interface} #{'--skip_rake_migrate' if options.skip_rake_migrate} #{'--skip_timestamp' if options.skip_timestamp} #{'--skip_questions' if options.skip_questions} --skip-migrations"
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def controller_and_view
|
60
|
+
unless options.skip_interface
|
61
|
+
# controllers
|
62
|
+
@inherit_controller = 'A::BackendController' if @model.space == 'a'
|
63
|
+
template "controllers/#{'ajax_' if options.ajax}controller.rb", "app/controllers/#{@model.space}/#{@model.plural_name}_controller.rb"
|
64
|
+
|
65
|
+
# views - update only
|
66
|
+
template 'views/update.js.erb', "app/views/#{@model.space}/#{@model.plural_name}/update.js.erb"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def model_and_migration
|
71
|
+
# model override
|
72
|
+
template 'model.rb', "app/models/#{@model.space}/#{@model.singular_name}.rb"
|
73
|
+
|
74
|
+
# override model attributes to not allow field duplicity (causing errorss)
|
75
|
+
@model.attributes = []
|
76
|
+
attributes.each do |attribute|
|
77
|
+
@model.add_attribute MDWA::Generators::ModelAttribute.new( attribute ) unless @predefined_fields.include?( attribute.split(':').first )
|
78
|
+
end
|
79
|
+
migration_template 'migrate.rb', "db/migrate/add_#{@model.attributes.collect{|a| a.name}.join('_')}_to_users" unless @model.attributes.empty?
|
80
|
+
|
81
|
+
# include type in db:seed
|
82
|
+
append_file 'db/seeds/site.rb' do
|
83
|
+
"\n\nPermission.create( :name => '#{@model.singular_name}' ) if Permission.find_by_name('#{@model.singular_name}').nil?"
|
84
|
+
end
|
85
|
+
# run rake db:seeds
|
86
|
+
if yes?('Run rake db:seed to create permission type?')
|
87
|
+
rake 'db:migrate'
|
88
|
+
rake 'db:seed'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def run_rake_db_migrate
|
94
|
+
if !options.skip_rake_migrate and !options.skip_migrations and !options.only_interface
|
95
|
+
rake('db:migrate') if !options.skip_questions and yes? 'Run rake db:migrate?'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
# Sets Rails migration timestamp
|
102
|
+
def self.next_migration_number(dirname) #:nodoc:
|
103
|
+
if ActiveRecord::Base.timestamped_migrations
|
104
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
105
|
+
else
|
106
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
data/lib/mdwa/dsl.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
+
require 'mdwa/dsl/entities'
|
2
3
|
module MDWA
|
3
4
|
module DSL
|
4
5
|
|
5
|
-
autoload :Entities, 'mdwa/dsl/entities'
|
6
6
|
autoload :Entity, 'mdwa/dsl/entity'
|
7
|
+
autoload :EntityAttribute, 'mdwa/dsl/entity_attribute'
|
8
|
+
autoload :EntityAssociation, 'mdwa/dsl/entity_association'
|
9
|
+
autoload :Generator, 'mdwa/dsl/generator'
|
10
|
+
|
11
|
+
STRUCTURAL_PATH = 'app/mdwa/structure/'
|
12
|
+
NAVIGATION_PATH = 'app/mdwa/navigation/'
|
7
13
|
|
8
14
|
end
|
9
15
|
end
|
data/lib/mdwa/dsl/entities.rb
CHANGED
@@ -15,12 +15,20 @@ module MDWA
|
|
15
15
|
@__instance__ ||= new
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
#
|
19
|
+
# Register a new entity in the list.
|
20
|
+
#
|
21
|
+
def register( name )
|
22
|
+
# retrive or initialize a entity
|
19
23
|
e = element(name) || Entity.new( name )
|
20
24
|
yield e
|
21
|
-
add_node e
|
25
|
+
add_node e # add to the list
|
22
26
|
end
|
23
27
|
|
28
|
+
#
|
29
|
+
# Add note to the entity list
|
30
|
+
# Prevents entity duplication
|
31
|
+
#
|
24
32
|
def add_node(node)
|
25
33
|
@nodes[node.name] = node
|
26
34
|
end
|
@@ -28,6 +36,10 @@ module MDWA
|
|
28
36
|
def element(e)
|
29
37
|
@nodes[e]
|
30
38
|
end
|
39
|
+
|
40
|
+
def all
|
41
|
+
@nodes.values
|
42
|
+
end
|
31
43
|
|
32
44
|
end # class entitites
|
33
45
|
|