freeRangeEggs 0.0.1 → 0.0.3.alpha

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 691f8e01abefa51c9775b4e5ece3f8efe59393b8
4
+ data.tar.gz: 96d7926e8fee9851918082eedfc30685b0af4c31
5
+ SHA512:
6
+ metadata.gz: 104e8cfc3bdbd293ae4bc15317bb532744284f192335d9fd71c4f50351ed2aed5692e07a7ab1a3555daff7e4c2e83aad202e3d64319e6c873ffc63403386dfdf
7
+ data.tar.gz: ce04f7af1dcb429e532833b6188e7a7dc3135a9f804ad7f0eb89ebd3a84d9fee62ed7f00f57d0154b45ea26f42bddd86c5e292947d5197b53d5c41fc1ff3ebb4
data/.DS_Store ADDED
Binary file
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # FreeRangeEggs
2
2
 
3
- TODO: Write a gem description
3
+ FreerRange Eggs is a gem for Ruby on Rails that convert the restricted JSON to Active Records. It is created to be a part of the honour project [erd_to_ac](https://github.com/jaxi/erd_to_ac), which convert the entity relationship diagram to Active Records.
4
+
5
+ Anyway, the gem is still under developing, and only the alpha version is available, hoping it will getting better.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
8
10
 
9
- gem 'freeRangeEggs'
11
+ gem 'freeRangeEggs' --pre
10
12
 
11
13
  And then execute:
12
14
 
@@ -18,7 +20,7 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ TODO: The spec would be written latter :-)
22
24
 
23
25
  ## Contributing
24
26
 
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
data/bin/fre ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ args = ARGV.dup
7
+ ARGV.clear
8
+
9
+ puts lib
10
+ require 'thor'
11
+ `ruby #{lib}/run.rb work #{args[0]}`
@@ -12,6 +12,8 @@ Gem::Specification.new do |gem|
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "freeRangeEggs"
15
+ gem.add_dependency 'rails'
16
+ gem.add_dependency 'rspec'
15
17
  gem.require_paths = ["lib"]
16
18
  gem.version = FreeRangeEggs::VERSION
17
19
  end
data/lib/data ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "models" : [
3
+
4
+ // Customer Model
5
+ {
6
+ "name" : "customer",
7
+ "attrs" : [
8
+ {
9
+ "name" : "id",
10
+ "type" : "integer"
11
+ },
12
+ {
13
+ "name" : "name",
14
+ "type" : "string"
15
+ }
16
+ ],
17
+ },
18
+
19
+ // Order Model
20
+ {
21
+ "name" : "order",
22
+ "attrs" : [
23
+ {
24
+ "name" : "id",
25
+ "type" : "integer"
26
+ },
27
+ {
28
+ "name" : "name",
29
+ "type" : "string"
30
+ },
31
+ {
32
+ "name" : "customer",
33
+ "type" : "references"
34
+ }
35
+
36
+ ]
37
+ }
38
+ }
@@ -1,3 +1,3 @@
1
1
  module FreeRangeEggs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3.alpha"
3
3
  end
data/lib/freeRangeEggs.rb CHANGED
@@ -1,7 +1,62 @@
1
1
  require "freeRangeEggs/version"
2
2
 
3
3
  module FreeRangeEggs
4
- def self.introduction
5
- "This is a component of the entities relationship diagram to active-record, which is the author's final project"
4
+ # The gems required
5
+ require 'json'
6
+ require 'erb'
7
+ require 'active_support/inflector'
8
+
9
+ class MigrationGenerator
10
+
11
+ attr_accessor :name, :attrs
12
+
13
+ def initialize(model)
14
+ @model_name = model["name"]
15
+ @attrs = model["attrs"] + [ {"name": "id", "type" : "integer"}]
16
+ end
17
+
18
+ def to_s
19
+ return "Model Name: #{@name} \n
20
+ Attributes: #{@attrs}"
21
+ end
22
+
23
+ def get_binding
24
+ binding
25
+ end
26
+
27
+ def get_result
28
+ migration = ERB.new(File.read("./templates/migration.erb"))
29
+ migration.run(self.get_binding)
30
+ end
31
+ end
32
+
33
+ class ModelGenerator
34
+ attr_accessor :model_name, :variables, :relationships
35
+
36
+ def initialize(model)
37
+ @model_name = model["model"]
38
+ @variables = model["attrs"] + [{"name": "id", "type" : "integer"}]
39
+ end
40
+
41
+ def to_s
42
+ return "Model Name: #{@name}\n
43
+ Attributes: #{@attrs}"
44
+ end
45
+
46
+ def get_binding
47
+ binding
48
+ end
49
+
50
+ def get_result
51
+ the_model = ERB.new(File.read("./templates/model.erb"))
52
+ the_model.run(self.get_binding)
53
+ end
54
+ end
55
+
56
+ class RelathionshipModelGenerator
57
+ end
58
+
59
+ class RelationshipMigrationGenerator
6
60
  end
61
+
7
62
  end
@@ -0,0 +1,12 @@
1
+ class Create<%= @name.capitalize.pluralize %> < ActiveRecord::Migration
2
+ def change
3
+ create table <%= @name.pluralize.to_sym %> do |t|
4
+ <% @attrs.each do |v| %>
5
+ t.<%= v["type"] %> <%= ":#{v['name']}" %><% end %>
6
+ t.timestamps
7
+ end
8
+ <% if @indexes %>
9
+ <% @indexes.each do |index| %>
10
+ add_index <%= name.pluralize.to_sym %>, index<% end %><% end %>
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ class <%= @name.capitalize %> < ActiveRecord::Base
2
+ attr_accessible <%= @attrs.map{ |x| ':' +x["name"]}.join(", ") %>
3
+ end
File without changes
metadata CHANGED
@@ -1,53 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freeRangeEggs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.3.alpha
6
5
  platform: ruby
7
6
  authors:
8
7
  - jaxi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-21 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
14
41
  description: This gem is used to convert the json to Active Records
15
42
  email:
16
43
  - jaxihe@gmail.com
17
- executables: []
44
+ executables:
45
+ - fre
18
46
  extensions: []
19
47
  extra_rdoc_files: []
20
48
  files:
49
+ - .DS_Store
21
50
  - .gitignore
51
+ - .rspec
22
52
  - Gemfile
23
53
  - LICENSE
24
54
  - README.md
25
55
  - Rakefile
56
+ - bin/fre
26
57
  - freeRangeEggs.gemspec
58
+ - lib/data
27
59
  - lib/freeRangeEggs.rb
28
60
  - lib/freeRangeEggs/version.rb
61
+ - lib/templates/migration.erb
62
+ - lib/templates/model.erb
63
+ - spec/spec_helper.rb
29
64
  homepage: https://github.com/jaxi
30
65
  licenses: []
66
+ metadata: {}
31
67
  post_install_message:
32
68
  rdoc_options: []
33
69
  require_paths:
34
70
  - lib
35
71
  required_ruby_version: !ruby/object:Gem::Requirement
36
- none: false
37
72
  requirements:
38
- - - ! '>='
73
+ - - '>='
39
74
  - !ruby/object:Gem::Version
40
75
  version: '0'
41
76
  required_rubygems_version: !ruby/object:Gem::Requirement
42
- none: false
43
77
  requirements:
44
- - - ! '>='
78
+ - - '>'
45
79
  - !ruby/object:Gem::Version
46
- version: '0'
80
+ version: 1.3.1
47
81
  requirements: []
48
82
  rubyforge_project:
49
- rubygems_version: 1.8.24
83
+ rubygems_version: 2.0.0
50
84
  signing_key:
51
- specification_version: 3
85
+ specification_version: 4
52
86
  summary: A lot of command to be written... Not NOW
53
- test_files: []
87
+ test_files:
88
+ - spec/spec_helper.rb