arfy 0.1 → 0.1.1
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/README.md +58 -0
- data/lib/arfy/application_faker.rb +17 -0
- data/lib/arfy/config_faker.rb +12 -0
- data/lib/arfy/environment_faker.rb +14 -0
- data/lib/arfy/generator.rb +23 -0
- data/lib/arfy/rails_faker.rb +27 -0
- data/lib/arfy/version.rb +3 -0
- data/lib/arfy.rb +24 -0
- data/lib/tasks/all.rb +28 -0
- metadata +13 -4
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Arfy
|
2
|
+
|
3
|
+
### Allow use ActiveRecord and Migration from Rails
|
4
|
+
## even if you don't use all Rails stack
|
5
|
+
|
6
|
+
This is a very early implementation, so any comments are wellcome, but
|
7
|
+
we are developing this on a daily basis. Huge changes in few days are
|
8
|
+
expected.
|
9
|
+
|
10
|
+
gem install arfy
|
11
|
+
|
12
|
+
On your project's folder, put a Rakefile.rb with:
|
13
|
+
|
14
|
+
require 'arfy'
|
15
|
+
|
16
|
+
Check if you are ready to go:
|
17
|
+
|
18
|
+
rake -T
|
19
|
+
|
20
|
+
You should see some familiar tasks:
|
21
|
+
|
22
|
+
rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
|
23
|
+
rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
|
24
|
+
rake db:fixtures:load # Load fixtures into the current environment's database.
|
25
|
+
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).
|
26
|
+
rake db:migrate:status # Display status of migrations
|
27
|
+
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n).
|
28
|
+
rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
|
29
|
+
rake db:schema:load # Load a schema.rb file into the database
|
30
|
+
rake db:seed # Load the seed data from db/seeds.rb
|
31
|
+
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
|
32
|
+
rake db:structure:dump # Dump the database structure to an SQL file
|
33
|
+
rake db:version # Retrieves the current schema version number
|
34
|
+
rake generate:migration # Generate migration (options NAME=migration_file_name, OUTDIR=db/migrate, TARGET=environment)
|
35
|
+
rake rails_env # Changes the environment (options TARGET=development) - use your's configuration name on database.yml
|
36
|
+
|
37
|
+
---
|
38
|
+
|
39
|
+
The goal here is to use the Migrations. The generator is coming soon,
|
40
|
+
but for now, you need to use the Rails conventions and create two dirs on
|
41
|
+
your project:
|
42
|
+
|
43
|
+
your_project/
|
44
|
+
db/migrate/
|
45
|
+
config/
|
46
|
+
|
47
|
+
Create your migration files, following the [Rails docs](http://api.rubyonrails.org/classes/ActiveRecord/Migration.html).
|
48
|
+
|
49
|
+
Inside config, create your database.yml, just like you can do with
|
50
|
+
[Rails](http://guides.rubyonrails.org/getting_started.html). On
|
51
|
+
db/migrate, put your migration files.
|
52
|
+
|
53
|
+
Now you can do:
|
54
|
+
|
55
|
+
rake db:create:all
|
56
|
+
rake db:migrate
|
57
|
+
|
58
|
+
Enjoy and, if you can, help me improve this tool.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RailsFaker
|
2
|
+
#https://github.com/rails/rails/blob/master/railties/lib/rails/application/configuration.rb
|
3
|
+
module ConfigFaker
|
4
|
+
def paths
|
5
|
+
configured_paths
|
6
|
+
end
|
7
|
+
|
8
|
+
def database_configuration
|
9
|
+
YAML::load(ERB.new(IO.read(paths["config/database"])).result)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RailsFaker
|
2
|
+
module EnvironmentFaker
|
3
|
+
attr_accessor :env
|
4
|
+
def method_missing(who_ami)
|
5
|
+
method = who_ami.to_s
|
6
|
+
ends_with_questionmark = method.index("?") == method.length - 1
|
7
|
+
if ends_with_questionmark
|
8
|
+
env_name_asked = method.slice(0, method.length-1)
|
9
|
+
return env_name_asked == ENV['RAILS_ENV'] || self.env
|
10
|
+
end
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#activerecord generators
|
2
|
+
#TODO: instalador com download dos arquivos rails de quem esse generator
|
3
|
+
#depende
|
4
|
+
# rails/generators/name_based: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/named_base.rb
|
5
|
+
# rails/generators/migration: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/migration.rb
|
6
|
+
# rails/generators/active_modle: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/active_model.rb
|
7
|
+
|
8
|
+
#require 'rails/generators/active_record'
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
require 'erb'
|
12
|
+
klass = "teste"
|
13
|
+
template = ERB.new <<EOF
|
14
|
+
<%= "class #{klass} < ActiveRecord::Migration" %>
|
15
|
+
<%= " def self.up" %>
|
16
|
+
<%= " end" %>
|
17
|
+
<%= "" %>
|
18
|
+
<%= " def self.down" %>
|
19
|
+
<%= " end" %>
|
20
|
+
<%= "end" %>
|
21
|
+
EOF
|
22
|
+
|
23
|
+
puts template.result
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RailsFaker
|
2
|
+
def root
|
3
|
+
"."
|
4
|
+
end
|
5
|
+
|
6
|
+
def env
|
7
|
+
if @fake_env.nil?
|
8
|
+
env_name = ENV['RAILS_ENV'] ||= "development"
|
9
|
+
@fake_env = Rails.application.config.database_configuration[env_name]
|
10
|
+
class << @fake_env
|
11
|
+
include EnvironmentFaker
|
12
|
+
end
|
13
|
+
end
|
14
|
+
@fake_env.env = env_name
|
15
|
+
@fake_env
|
16
|
+
end
|
17
|
+
|
18
|
+
def application
|
19
|
+
if @fake_application.nil?
|
20
|
+
@fake_application = Object.new
|
21
|
+
class << @fake_application
|
22
|
+
include ApplicationFaker
|
23
|
+
end
|
24
|
+
end
|
25
|
+
@fake_application
|
26
|
+
end
|
27
|
+
end
|
data/lib/arfy/version.rb
ADDED
data/lib/arfy.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
require 'arfy/config_faker'
|
5
|
+
require 'arfy/application_faker'
|
6
|
+
require 'arfy/environment_faker'
|
7
|
+
require 'arfy/rails_faker'
|
8
|
+
|
9
|
+
def configured_paths
|
10
|
+
paths = {}
|
11
|
+
paths["config/database"] = "config/database.yml"
|
12
|
+
migrate_path = String.new("db/migrate")
|
13
|
+
def migrate_path.to_a
|
14
|
+
[self]
|
15
|
+
end
|
16
|
+
paths["db/migrate"] = migrate_path
|
17
|
+
paths
|
18
|
+
end
|
19
|
+
|
20
|
+
class Rails
|
21
|
+
extend RailsFaker
|
22
|
+
end
|
23
|
+
|
24
|
+
require "tasks/all"
|
data/lib/tasks/all.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
task :environment do
|
2
|
+
# requiring config/environment
|
3
|
+
end
|
4
|
+
|
5
|
+
desc "Changes the environment (options TARGET=development) - use your's configuration name on database.yml"
|
6
|
+
task :rails_env do
|
7
|
+
ENV['RAILS_ENV'] = ENV["TARGET"] || "development"
|
8
|
+
unless defined? RAILS_ENV
|
9
|
+
RAILS_ENV = ENV['RAILS_ENV']
|
10
|
+
end
|
11
|
+
|
12
|
+
# TODO: waiting for a better way of doing this
|
13
|
+
# create a new connection on pool for ActiveRecord::Base class name
|
14
|
+
# TODO: just do it on the first time
|
15
|
+
ActiveRecord::Base.establish_connection(Rails.env)
|
16
|
+
end
|
17
|
+
|
18
|
+
namespace :generate do
|
19
|
+
desc "Generate migration (options NAME=migration_file_name, OUTDIR=db/migrate, TARGET=environment)"
|
20
|
+
task :migration do
|
21
|
+
ENV['RAILS_ENV'] = ENV["TARGET"] || (ENV["RAILS_ENV"] || "development")
|
22
|
+
dir = ENV['OUTDIR'] || Rails.application.config.paths['db/migrate']
|
23
|
+
|
24
|
+
puts 'not yet implemented'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
load 'active_record/railties/databases.rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arfy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-20 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70171151577780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70171151577780
|
25
25
|
description: ! 'Arfy is just a snippet: some rake tasks and environment configuration
|
26
26
|
to allow you use Rails migrations, without all the rails stack.'
|
27
27
|
email:
|
@@ -29,7 +29,16 @@ email:
|
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
|
-
files:
|
32
|
+
files:
|
33
|
+
- lib/arfy/application_faker.rb
|
34
|
+
- lib/arfy/config_faker.rb
|
35
|
+
- lib/arfy/environment_faker.rb
|
36
|
+
- lib/arfy/generator.rb
|
37
|
+
- lib/arfy/rails_faker.rb
|
38
|
+
- lib/arfy/version.rb
|
39
|
+
- lib/arfy.rb
|
40
|
+
- lib/tasks/all.rb
|
41
|
+
- README.md
|
33
42
|
homepage: http://github.com/ricardovaleriano/arfy
|
34
43
|
licenses: []
|
35
44
|
post_install_message:
|