grn 0.1.1 → 0.2.0
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/grn.gemspec +0 -1
- data/lib/generators/grn/install/install_generator.rb +16 -0
- data/lib/generators/grn/install/templates/inflections.rb +5 -0
- data/lib/generators/grn/{USAGE → p1/USAGE} +0 -0
- data/lib/generators/grn/p1/p1_generator.rb +35 -0
- data/lib/generators/grn/p1/templates/recurso.rb +43 -0
- data/lib/generators/grn/p1/templates/tipo_recurso.rb +32 -0
- data/lib/grn.rb +1 -4
- data/lib/grn/version.rb +1 -1
- metadata +8 -22
- data/lib/generators/grn/p1_generator.rb +0 -78
- data/lib/grn/resource.rb +0 -12
- data/lib/grn/resource_type.rb +0 -12
data/grn.gemspec
CHANGED
@@ -9,7 +9,6 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.summary = "Implementa classes de apoio para a linguagem de padrões GRN e cria geradores para cada padrão."
|
10
10
|
gem.homepage = "https://github.com/marcelotheodoro/grn"
|
11
11
|
|
12
|
-
gem.add_dependency 'rails'
|
13
12
|
gem.add_dependency 'mdd'
|
14
13
|
|
15
14
|
gem.files = `git ls-files`.split($\)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module Grn
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
|
+
|
10
|
+
def inflections
|
11
|
+
template 'inflections.rb', 'config/initializers/grn_inflections.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
end # class
|
15
|
+
end # generators
|
16
|
+
end # grn
|
File without changes
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
require 'mdwa/dsl'
|
5
|
+
|
6
|
+
module Grn
|
7
|
+
module Generators
|
8
|
+
class P1Generator < Rails::Generators::Base
|
9
|
+
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
11
|
+
|
12
|
+
attr_accessor :recurso_nome, :tipo_recurso_nome
|
13
|
+
|
14
|
+
class_option :nomes_padroes, :type => :boolean, :default => false, :desc => 'Usar nomes padrões. "Recurso" para recurso e "TipoRecurso" para tipo de recurso.'
|
15
|
+
|
16
|
+
def initialize(*args, &block)
|
17
|
+
super
|
18
|
+
|
19
|
+
unless options.nomes_padroes
|
20
|
+
@recurso_nome = ask('Nome do recurso:')
|
21
|
+
@tipo_recurso_nome = ask('Nome do tipo do recurso:')
|
22
|
+
end
|
23
|
+
@recurso_nome = 'Recurso' if @recurso_nome.blank?
|
24
|
+
@tipo_recurso_nome = 'TipoRecurso' if @tipo_recurso_nome.blank?
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def gerar_arquivos
|
29
|
+
template 'recurso.rb', "#{MDWA::DSL::STRUCTURAL_PATH}#{MDWA::DSL::Entity.new(@recurso_nome).file_name}.rb"
|
30
|
+
template 'tipo_recurso.rb', "#{MDWA::DSL::STRUCTURAL_PATH}#{MDWA::DSL::Entity.new(@tipo_recurso_nome).file_name}.rb"
|
31
|
+
end
|
32
|
+
|
33
|
+
end # class
|
34
|
+
end # generators
|
35
|
+
end # grn
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'mdwa/dsl'
|
3
|
+
MDWA::DSL.entities.register "<%= @recurso_nome %>" do |e|
|
4
|
+
|
5
|
+
e.resource = true # should it be stored like a resource?
|
6
|
+
e.ajax = true # scaffold with ajax?
|
7
|
+
e.scaffold_name = 'a/<%= @recurso_nome.underscore %>' # mdwa sandbox specific code?
|
8
|
+
e.model_name = 'a/<%= @recurso_nome.underscore %>' # use specific model name? or different namespace?
|
9
|
+
|
10
|
+
##
|
11
|
+
## Define entity attributes
|
12
|
+
##
|
13
|
+
e.attribute do |attr|
|
14
|
+
attr.name = 'descricao'
|
15
|
+
attr.type = 'string'
|
16
|
+
end
|
17
|
+
|
18
|
+
e.attribute do |attr|
|
19
|
+
attr.name = 'preco'
|
20
|
+
attr.type = 'decimal'
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
## Define entity associations
|
25
|
+
##
|
26
|
+
e.association do |a|
|
27
|
+
a.type = 'many_to_one'
|
28
|
+
a.destination = '<%= @tipo_recurso_nome %>'
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
## Entity specifications.
|
33
|
+
## Define restrictions and rules so this entity will work properly.
|
34
|
+
##
|
35
|
+
e.specify "campos devem ser validos" do |s|
|
36
|
+
s.such_as "nome não pode ser nulo"
|
37
|
+
s.such_as "preço não pode ser nulo"
|
38
|
+
s.such_as "categoria não pode ser nula"
|
39
|
+
end
|
40
|
+
e.specify "valor deve ser maior que zero"
|
41
|
+
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'mdwa/dsl'
|
3
|
+
MDWA::DSL.entities.register "<%= @tipo_recurso_nome %>" do |e|
|
4
|
+
|
5
|
+
e.resource = true # should it be stored like a resource?
|
6
|
+
e.ajax = true # scaffold with ajax?
|
7
|
+
e.scaffold_name = 'a/<%= @tipo_recurso_nome.underscore %>' # mdwa sandbox specific code?
|
8
|
+
e.model_name = 'a/<%= @tipo_recurso_nome.underscore %>' # use specific model name? or different namespace?
|
9
|
+
|
10
|
+
##
|
11
|
+
## Define entity attributes
|
12
|
+
##
|
13
|
+
e.attribute do |attr|
|
14
|
+
attr.name = 'name'
|
15
|
+
attr.type = 'string'
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
## Define entity associations
|
20
|
+
##
|
21
|
+
e.association do |a|
|
22
|
+
a.type = 'one_to_many'
|
23
|
+
a.destination = '<%= @recurso_nome %>' # entity name
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
## Entity specifications.
|
28
|
+
## Define restrictions and rules so this entity will work properly.
|
29
|
+
##
|
30
|
+
e.specify "nome não pode ser nulo"
|
31
|
+
|
32
|
+
end
|
data/lib/grn.rb
CHANGED
data/lib/grn/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rails
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
14
|
- !ruby/object:Gem::Dependency
|
31
15
|
name: mdd
|
32
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,11 +40,13 @@ files:
|
|
56
40
|
- README.md
|
57
41
|
- Rakefile
|
58
42
|
- grn.gemspec
|
59
|
-
- lib/generators/grn/
|
60
|
-
- lib/generators/grn/
|
43
|
+
- lib/generators/grn/install/install_generator.rb
|
44
|
+
- lib/generators/grn/install/templates/inflections.rb
|
45
|
+
- lib/generators/grn/p1/USAGE
|
46
|
+
- lib/generators/grn/p1/p1_generator.rb
|
47
|
+
- lib/generators/grn/p1/templates/recurso.rb
|
48
|
+
- lib/generators/grn/p1/templates/tipo_recurso.rb
|
61
49
|
- lib/grn.rb
|
62
|
-
- lib/grn/resource.rb
|
63
|
-
- lib/grn/resource_type.rb
|
64
50
|
- lib/grn/version.rb
|
65
51
|
homepage: https://github.com/marcelotheodoro/grn
|
66
52
|
licenses: []
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
|
-
require 'rails/generators'
|
4
|
-
|
5
|
-
require 'mdd/generators/model'
|
6
|
-
require 'mdd/generators/model_attribute'
|
7
|
-
|
8
|
-
module Grn
|
9
|
-
module Generators
|
10
|
-
class P1Generator < Rails::Generators::Base
|
11
|
-
|
12
|
-
attr_accessor :resource_type_name, :resource_type_attributes, :resource_name, :resource_attributes, :resource, :resource_type
|
13
|
-
|
14
|
-
class_option :type_name, :desc => 'Resource type name', :type => :string
|
15
|
-
class_option :type_attributes, :desc => 'Resource type attributes', :type => :string
|
16
|
-
|
17
|
-
class_option :resource_name, :desc => 'Resource name', :type => :string
|
18
|
-
class_option :resource_attributes, :desc => 'Resource attributes', :type => :string
|
19
|
-
|
20
|
-
def initialize(*args, &block)
|
21
|
-
|
22
|
-
super
|
23
|
-
|
24
|
-
# resource type
|
25
|
-
@resource_type_name = options.type_name || ask("\nChoose the resource type name.\nExample: Category, ProductCategory, etc.\nResource type name:")
|
26
|
-
@resource_type = Mdd::Generators::Model.new( @resource_type_name )
|
27
|
-
print_usage unless @resource_type.valid?
|
28
|
-
|
29
|
-
#resource type attributes
|
30
|
-
@resource_type_attributes = options.type_attributes || ask("\n=============================\nChoose the resource type attributes.\nSyntax: similar to MDD gem. Description is already included.\nResource type attributes:")
|
31
|
-
@resource_type_attributes.split(' ').each do |attribute|
|
32
|
-
@resource_type.add_attribute Mdd::Generators::ModelAttribute.new( attribute )
|
33
|
-
end
|
34
|
-
|
35
|
-
# resource
|
36
|
-
@resource_name = options.resource_name || ask("\n=============================\nChoose the resource name.\nExample: Product, Movie, Equipment, etc.\nResource name:")
|
37
|
-
@resource = Mdd::Generators::Model.new( @resource_name )
|
38
|
-
print_usage unless @resource.valid?
|
39
|
-
|
40
|
-
# resource attributes
|
41
|
-
@resource_attributes = options.resource_attributes || ask("\n=============================\nChoose the resource attributes.\nSyntax: similar to MDD gem. Description is already included.\nResource attributes:")
|
42
|
-
@resource_attributes.split(' ').each do |attribute|
|
43
|
-
@resource.add_attribute Mdd::Generators::ModelAttribute.new( attribute )
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
def mdd_associations
|
50
|
-
|
51
|
-
# resouce type
|
52
|
-
# generate the scaffold with the attributes
|
53
|
-
generate "mdd:scaffold #{@resource_type.raw} description:string #{@resource_type.attributes.map{ |attr| attr.raw }.join(' ')}"
|
54
|
-
|
55
|
-
# resouce
|
56
|
-
# generate the scaffold with the attributes and belongs_to resource type
|
57
|
-
generate "mdd:scaffold #{@resource.raw} description:string #{@resource.attributes.map{ |attr| attr.raw }.join(' ')} #{@resource_type.singular_name}:#{@resource_type.raw}:description:belongs_to"
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
def insert_into_classes
|
63
|
-
|
64
|
-
# resource type
|
65
|
-
inject_into_class "app/models/#{@resource_type.space}/#{@resource_type.singular_name}.rb", @resource_type.klass.classify.constantize do
|
66
|
-
"include Grn::ResourceType"
|
67
|
-
end
|
68
|
-
|
69
|
-
# resource
|
70
|
-
inject_into_class "app/models/#{@resource.space}/#{@resource.singular_name}.rb", @resource.klass.classify.constantize do
|
71
|
-
"include Grn::Resource"
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
end # class
|
77
|
-
end # generators
|
78
|
-
end # grn
|
data/lib/grn/resource.rb
DELETED