grn 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,78 @@
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.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require "grn/version"
2
2
 
3
3
  module Grn
4
- # Your code goes here...
4
+
5
+ autoload :Resource, 'grn/resource'
6
+ autoload :ResourceType, 'grn/resource_type'
7
+
5
8
  end
@@ -0,0 +1,12 @@
1
+ module Grn
2
+
3
+ module Resource
4
+
5
+ # override
6
+ # identify the resource type according to GRN first pattern
7
+ def resource_type
8
+ end
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ module Grn
2
+
3
+ module ResourceType
4
+
5
+ # override
6
+ # identify the resource according to GRN first pattern
7
+ def resource
8
+ end
9
+
10
+ end
11
+
12
+ end
data/lib/grn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Grn
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
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.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -56,7 +56,11 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - grn.gemspec
59
+ - lib/generators/grn/USAGE
60
+ - lib/generators/grn/p1_generator.rb
59
61
  - lib/grn.rb
62
+ - lib/grn/resource.rb
63
+ - lib/grn/resource_type.rb
60
64
  - lib/grn/version.rb
61
65
  homepage: https://github.com/marcelotheodoro/grn
62
66
  licenses: []