to_elixir 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46d21dd0fcfd706799e3299d398745589f26842b
4
+ data.tar.gz: 71751fcdfe586e7bc82fe79b2b1c856a38e5787e
5
+ SHA512:
6
+ metadata.gz: 9621d133c5f5f4015e192c08b44ad630c4bc1a44a817bde141099eaaa0e1620dd30c3eb9291f199774c929c5352d19167b27f15ef767d7c870095fa6b3ba7a6a
7
+ data.tar.gz: d2fb7ed490db8c5745b9c9cdef233ed97368702487179c7f61f63ecd2e26534ad8ae639f9041b292cf8e91d0ad765d8b6c164050c0322f336cf507f4e99c0ef9
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at matt.darby@rackspace.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in to_elixir.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Matt Darby
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # to_elixir
2
+
3
+ to_elixir is a super simple Rails rake task that inspects your existing Rails application and generates a Elixir / Phoenix JSON API.
4
+
5
+ ## Install
6
+ Add `gem :to_elixir` to your `Gemfile` and run `bundle install`
7
+
8
+ ## Usage
9
+ `rake to_elixir:phoenix APP_NAME=<NAME>`
10
+
11
+ Where `<NAME>` is the name of your new Elixir app.
12
+ This will create a folder `<NAME>` in the root of your Rails application.
13
+ Simply run the command, wait a tick and then move the resulting folder somewhere else.
14
+ Enter the new Elixir app and run `iex -S mix phoenix.server` to boot your Elixir app.
15
+ Load up your new app at `http://localhost:4000/api/<EXISTING_RESOURCE_NAME>` and boom; simple json api.
16
+
17
+ ## Want your data in that API?
18
+ `rake to_elixir:timestamps`
19
+
20
+ If you'd like to convert your existing Rails-based DB over to Phoenix just run the above command.
21
+ This will create a Rails migration that renames `:created_at` to `:inserted_at`
22
+ It can be rolled back (`rake db:rollback`) and is non-destructive.
23
+ Update `config/dev.exs` to point to your migrated Rails DB and viola; data in your simple json api.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "to_elixir"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,111 @@
1
+ namespace :to_elixir do
2
+ desc "Generate Rails migration for created_at timestamps"
3
+ task :timestamps => :environment do
4
+ time = Time.now.strftime('%Y%m%d%H%M%S')
5
+
6
+ File.open "#{Rails.root}/db/migrate/#{time}_convert_timestamps.rb", "wb" do |f|
7
+ f.write %{class ConvertTimestamps < ActiveRecord::Migration
8
+ def up
9
+ ActiveRecord::Base.connection.tables.each do |t|
10
+ begin
11
+ columns = t.classify.constantize.columns.map(&:name)
12
+
13
+ if columns.include?("created_at")
14
+ rename_column t.to_sym, :created_at, :inserted_at
15
+ end
16
+ rescue
17
+ puts "\#{t} failed."
18
+ end
19
+ end
20
+ end
21
+
22
+ def down
23
+ ActiveRecord::Base.connection.tables.each do |t|
24
+ begin
25
+ columns = t.classify.constantize.columns.map(&:name)
26
+
27
+ if columns.include?("inserted_at")
28
+ rename_column t.to_sym, :inserted_at, :created_at
29
+ end
30
+ rescue
31
+ puts "\#{t} failed."
32
+ end
33
+ end
34
+ end
35
+ end
36
+ }
37
+ end
38
+ end
39
+
40
+
41
+ desc "Generate Phoenix files from DB"
42
+ task :phoenix => :environment do
43
+ raise "No APP_NAME?" unless name = ENV['APP_NAME']
44
+
45
+ name = name.downcase
46
+ forget_list = %w{id updated_at created_at}
47
+ table_info = []
48
+
49
+ `rm -rf #{Dir.pwd}/#{name}`
50
+
51
+ puts "Creating #{name} Phoenix project"
52
+ `yes | mix phoenix.new #{name}`
53
+
54
+ puts "Creating DB"
55
+ Dir.chdir name
56
+ `mix ecto.create`
57
+
58
+ ActiveRecord::Base.connection.tables.each do |table|
59
+ begin
60
+ klass_name = table.singularize.camelize
61
+ klass = klass_name.constantize
62
+ obj_name = klass_name.tableize.singularize
63
+ columns = klass.columns
64
+ .reject{ |c| forget_list.include?(c.name) }
65
+ .map{ |c| "#{c.name}:#{c.type}" }
66
+ .join(" ")
67
+
68
+ puts "Mixing #{klass_name}..."
69
+ `sleep 1 && mix phoenix.gen.json #{klass_name} #{obj_name.pluralize} #{columns}`
70
+ table_info << [klass_name, obj_name]
71
+ rescue
72
+ puts "Not able to convert #{table}"
73
+ end
74
+ end
75
+
76
+ app_name = name.capitalize
77
+ router_path = "#{Dir.pwd}/web/router.ex"
78
+ routes = table_info.map{ |(k,o)| "\t\tresources \"/#{o.pluralize}\", #{k}Controller\n" }.join
79
+ template = %{defmodule #{app_name}.Router do
80
+ use #{app_name}.Web, :router
81
+
82
+ pipeline :browser do
83
+ plug :accepts, ["html"]
84
+ plug :fetch_session
85
+ plug :fetch_flash
86
+ plug :protect_from_forgery
87
+ plug :put_secure_browser_headers
88
+ end
89
+
90
+ pipeline :api do
91
+ plug :accepts, ["json"]
92
+ end
93
+
94
+ scope "/", #{app_name} do
95
+ pipe_through :browser # Use the default browser stack
96
+
97
+ get "/", PageController, :index
98
+ end
99
+
100
+ # Other scopes may use custom stacks.
101
+ scope "/api", #{app_name} do
102
+ pipe_through :api
103
+ #{routes}
104
+ end
105
+ end}
106
+
107
+ File.write(router_path, template)
108
+
109
+ `mix ecto.migrate`
110
+ end
111
+ end
data/lib/to_elixir.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "to_elixir/version"
2
+
3
+ module ToElixir
4
+ class MyRailtie < Rails::Railtie
5
+ rake_tasks do
6
+ load "to_elixir.rake"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ToElixir
2
+ VERSION = "0.1.0"
3
+ end
data/to_elixir.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'to_elixir/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "to_elixir"
8
+ spec.version = ToElixir::VERSION
9
+ spec.authors = ["Matt Darby"]
10
+ spec.email = ["matt.darby@rackspace.com"]
11
+
12
+ spec.summary = %q{Easily convert your existing Ruby/Rails API to Elixir/Phoenix!}
13
+ spec.description = %q{Easily convert your existing Ruby/Rails API to Elixir/Phoenix!}
14
+ spec.homepage = "https://github.com/rackerlabs/to_elixir"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_elixir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Darby
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Easily convert your existing Ruby/Rails API to Elixir/Phoenix!
56
+ email:
57
+ - matt.darby@rackspace.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/to_elixir.rake
73
+ - lib/to_elixir.rb
74
+ - lib/to_elixir/version.rb
75
+ - to_elixir.gemspec
76
+ homepage: https://github.com/rackerlabs/to_elixir
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Easily convert your existing Ruby/Rails API to Elixir/Phoenix!
100
+ test_files: []
101
+ has_rdoc: