appgen 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 124c8365461d39d54d076e72bfcfa7171e8b9455
4
- data.tar.gz: 3b5e05aef2ea8a74723f22503e77c7bdc55822f1
3
+ metadata.gz: ca0df51490f348d4940655c3e787dd2701644bac
4
+ data.tar.gz: 67395efe129160f5b0b6f3c5701ea5dbac757dbf
5
5
  SHA512:
6
- metadata.gz: c9aec89cfeb9030555749eb66c15dfa2db72e6642679ad916e4f3e13529e559d3876780695517f0dfb44e1b0c57ea77aa1413e63045febd1ba4716101d54a637
7
- data.tar.gz: 51329008b640be887dffb1499487a1e902309c2bf3390d2767dcbb29f3d893f94f8dee91d9f4b6cbeeb17c8f574a34bb21ab6ccb846dd133db5f1ed2ee727878
6
+ metadata.gz: 7f782095b1452ec44344a3bd0219cafb68d328f25c59ef151e1249693f6f8cf93c329336f946d9683e1084b66a07be88f4eb4bde35f5eb3cc7c6ce850fe90383
7
+ data.tar.gz: 976a4a455ada5c848a714acbfd1eb3cba94a269a996fe20ca35e3ed7f29328743922a4e153e9f82c3716b359cf3b83fbcbb2509fe2ebb1e53e04b951c024f22c
data/README.md CHANGED
@@ -36,6 +36,9 @@ Here is the rails blog demonstration as appgen description:
36
36
  There are comments.
37
37
  A comment has a user.
38
38
 
39
+ Some more descriptions in examples folder.
40
+ Feel free to contribute with yours!
41
+
39
42
  ### Hosting
40
43
 
41
44
  And if you want to host it on heroku, just add:
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.15"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "byebug"
24
25
  end
@@ -4,4 +4,4 @@ A post has a title, a text (as text), a user, and comments.
4
4
  There are users.
5
5
  A user has a name.
6
6
  There are comments.
7
- A comment has a user.
7
+ A comment has a user.
@@ -4,7 +4,7 @@ require 'appgen/generator'
4
4
  module Appgen
5
5
  class CLI
6
6
  def self.execute(path=nil)
7
- puts 'Welcome to Appgen'
7
+ puts 'Appgen'
8
8
  app = Appgen::Loader.load path
9
9
  Appgen::Generator.generate app
10
10
  end
@@ -1,7 +1,80 @@
1
+ require 'active_support/inflector'
2
+
1
3
  module Appgen
2
4
  class Generator
3
- def self.generate(app)
4
- puts 'Generating app'
5
+ def self.generate(app_description)
6
+ Generator.new app_description
7
+ end
8
+
9
+ def initialize(app_description)
10
+ @app_description = app_description
11
+ @lines = @app_description.lines
12
+ @entities = {}
13
+ find_app_name
14
+ find_entities
15
+ find_items
16
+ generate_app
17
+ generate_entities
18
+ end
19
+
20
+ protected
21
+
22
+ KEY_APP_NAME = 'The app name is '
23
+ KEY_ENTITY = 'There are '
24
+ KEY_ENTITY_DESCRIPTION = 'A '
25
+ KEY_ENTITY_SEPARATOR = ' has '
26
+ KEY_ITEM_DESCRIPTION = 'a '
27
+ KEY_ITEM_DESCRIPTION_LAST = 'and '
28
+
29
+ def find_app_name
30
+ @lines.each do |line|
31
+ if line.start_with? KEY_APP_NAME
32
+ @app_name = line.gsub(KEY_APP_NAME, '').gsub('.', '').chomp
33
+ end
34
+ end
35
+ end
36
+
37
+ def find_entities
38
+ @lines.each do |line|
39
+ if line.start_with? KEY_ENTITY
40
+ entity = line.gsub(KEY_ENTITY, '').gsub('.', '').chomp.singularize
41
+ @entities[entity] = {}
42
+ end
43
+ end
44
+ end
45
+
46
+ def find_items
47
+ @lines.each do |line|
48
+ if line.start_with? KEY_ENTITY_DESCRIPTION
49
+ split = line.gsub(KEY_ENTITY_DESCRIPTION, '').split(KEY_ENTITY_SEPARATOR)
50
+ entity = split[0]
51
+ description = split[1]
52
+ description.split(', ').each do |item|
53
+ clean_item = item.gsub(KEY_ITEM_DESCRIPTION, '').gsub(KEY_ITEM_DESCRIPTION_LAST, '').gsub('.', '').chomp
54
+ name = clean_item.split(' ')[0]
55
+ type = 'string'
56
+ # TODO other types (text, boolean, float)
57
+ # TODO references
58
+ @entities[entity][name] = type
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def generate_app
65
+ run "rails new #{@app_name} -d postgresql"
66
+ end
67
+
68
+ def generate_entities
69
+ @entities.each do |key, value|
70
+ values = value.map { |k, v| "#{k}:#{v}"}.join(' ')
71
+ run "cd #{@app_name}; rails g scaffold #{key} #{values}"
72
+ end
73
+ end
74
+
75
+ def run(command)
76
+ puts "$ #{command}"
77
+ system command
5
78
  end
6
79
  end
7
80
  end
@@ -4,7 +4,7 @@ module Appgen
4
4
  class Loader
5
5
  def self.load(path=nil)
6
6
  path = find_local_path if path.nil?
7
- puts 'No description found, you should add an app description in a file, or call appgen with a path or url.' and return if path.nil?
7
+ puts ' No description found, you should add an app description in a file, or call appgen with a path or url.' and return if path.nil?
8
8
  read_description path
9
9
  end
10
10
 
@@ -12,16 +12,14 @@ module Appgen
12
12
  Dir['*'].each do |entry|
13
13
  next if File.directory? entry
14
14
  next if entry.start_with? '.'
15
- puts "Found file named #{entry}"
15
+ puts " Found file named #{entry}"
16
16
  return entry
17
17
  end
18
18
  end
19
19
 
20
20
  def self.read_description(path)
21
- puts "Loading app description from #{path}"
22
- app = open(path) { |f| f.read }
23
- puts app
24
- app
21
+ puts " Loading app description from #{path}"
22
+ open(path) { |f| f.read }
25
23
  end
26
24
  end
27
25
  end
@@ -1,3 +1,3 @@
1
1
  module Appgen
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Levy
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description:
42
56
  email:
43
57
  - contact@arnaudlevy.com