arfy 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Arfy
2
-
3
- ### Allow use ActiveRecord and Migration from Rails
4
- ## even if you don't use all Rails stack
2
+ ## Allow use ActiveRecord and Migration from Rails
3
+ (even if you don't use all Rails stack)
5
4
 
6
5
  This is a very early implementation, so any comments are wellcome, but
7
6
  we are developing this on a daily basis. Huge changes in few days are
@@ -36,14 +35,21 @@ You should see some familiar tasks:
36
35
 
37
36
  ---
38
37
 
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
-
38
+ The goal here is to use the Migrations. You can use the Rails conventions and create two dirs on your project:
43
39
  your_project/
44
40
  db/migrate/
45
41
  config/
46
42
 
43
+ To generate a skeleton for a migration, use the task:
44
+
45
+ rake generate:migration NAME=my-MigrationName
46
+
47
+ (The awkward name here is just to illustrate that the task will create a file with a pretty name for you, something like:
48
+ 20110920000101_my_migration_name.rb)
49
+
50
+ A new file, with the timestamp as a prefix on name, will be generated on
51
+ db/migrate or on the path pointed by the OUTDIR option.
52
+
47
53
  Create your migration files, following the [Rails docs](http://api.rubyonrails.org/classes/ActiveRecord/Migration.html).
48
54
 
49
55
  Inside config, create your database.yml, just like you can do with
@@ -1,7 +1,6 @@
1
1
  module RailsFaker
2
2
  module EnvironmentFaker
3
- attr_accessor :env
4
- def method_missing(who_ami)
3
+ def method_missing(who_ami, *params)
5
4
  method = who_ami.to_s
6
5
  ends_with_questionmark = method.index("?") == method.length - 1
7
6
  if ends_with_questionmark
@@ -1,16 +1,3 @@
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
- #
11
-
12
- # heavily inspired/copyied from: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/migration.rb
13
-
14
1
  require 'erb'
15
2
 
16
3
  module StringPimped
@@ -44,30 +31,39 @@ end
44
31
 
45
32
  module Arfy
46
33
  class Generator
34
+ def generate_migration_file(migration_name, dir)
35
+ migration_path = File.join(dir, new_migration_file_name_for(migration_name))
36
+ File.open(migration_path, "w") do |file|
37
+ file << code_for_migration(migration_name)
38
+ end
39
+ return nil unless File.exists? migration_path
40
+ migration_path
41
+ end
42
+
43
+ private
44
+
47
45
  def timestamp
48
46
  Time.new.strftime("%Y%m%d%H%M%S")
49
47
  end
50
48
 
51
- def code_for_migration(migration_name)
52
- migration_name = String.new(migration_name)
53
- unless migration_name.respond_to? :classify
54
- class << migration_name
49
+ def pimp_this_string_for_method(string, method)
50
+ new_string = String.new(string)
51
+ unless new_string.respond_to? method
52
+ class << new_string
55
53
  include StringPimped
56
54
  end
57
55
  end
58
- klass = migration_name.classify
56
+ new_string.send(method)
57
+ end
58
+
59
+ def code_for_migration(migration_name)
60
+ klass = pimp_this_string_for_method(migration_name, :classify)
59
61
  b = binding
60
62
  template.result b
61
63
  end
62
64
 
63
65
  def new_migration_file_name_for(migration_name)
64
- migration_name = String.new(migration_name)
65
- unless migration_name.respond_to? :underscore
66
- class << migration_name
67
- include StringPimped
68
- end
69
- end
70
- migration_name = migration_name.underscore
66
+ migration_name = pimp_this_string_for_method(migration_name, :underscore)
71
67
  "#{timestamp}_#{migration_name}.rb"
72
68
  end
73
69
 
@@ -88,27 +84,5 @@ module Arfy
88
84
  ERB.new read_template_file
89
85
  end
90
86
 
91
- def generate_migration_file(migration_name, dir)
92
- migration_path = File.join(dir, new_migration_file_name_for(migration_name))
93
- File.open(migration_path, "w") do |file|
94
- file << code_for_migration(migration_name)
95
- end
96
- File.exists? migration_path
97
- end
98
87
  end
99
88
  end
100
-
101
- =begin
102
- klass = "teste"
103
- template = ERB.new <<EOF
104
- <%= "class #{klass} < ActiveRecord::Migration" %>
105
- <%= " def self.up" %>
106
- <%= " end" %>
107
- <%= "" %>
108
- <%= " def self.down" %>
109
- <%= " end" %>
110
- <%= "end" %>
111
- EOF
112
-
113
- puts template.result
114
- =end
@@ -5,13 +5,11 @@ module RailsFaker
5
5
 
6
6
  def env
7
7
  if @fake_env.nil?
8
- env_name = ENV['RAILS_ENV'] ||= "development"
9
- @fake_env = Rails.application.config.database_configuration[env_name]
8
+ @fake_env = String.new(ENV['RAILS_ENV'] ||= "development")
10
9
  class << @fake_env
11
10
  include EnvironmentFaker
12
11
  end
13
12
  end
14
- @fake_env.env = env_name
15
13
  @fake_env
16
14
  end
17
15
 
data/lib/arfy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arfy
2
- VERSION = "0.1.3" unless defined?(::Arfy::VERSION)
2
+ VERSION = "0.1.5" unless defined?(::Arfy::VERSION)
3
3
  end
data/lib/tasks/all.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  task :environment do
2
2
  # requiring config/environment
3
+ ActiveRecord::Base.establish_connection(Rails.application.config.database_configuration[Rails.env])
3
4
  end
4
5
 
5
6
  desc "Changes the environment (options TARGET=development) - use your's configuration name on database.yml"
@@ -12,7 +13,6 @@ task :rails_env do
12
13
  # TODO: waiting for a better way of doing this
13
14
  # create a new connection on pool for ActiveRecord::Base class name
14
15
  # TODO: just do it on the first time
15
- ActiveRecord::Base.establish_connection(Rails.env)
16
16
  end
17
17
 
18
18
  namespace :generate do
@@ -24,10 +24,15 @@ namespace :generate do
24
24
  outdir = ENV["OUTDIR"] || Rails.application.config.paths['db/migrate']
25
25
  ENV["RAILS_ENV"] = ENV["TARGET"] || ENV["RAILS_ENV"]
26
26
 
27
+ puts "working on environment: #{ENV['RAILS_ENV']}" if ENV["RAILS_ENV"]
28
+
27
29
  generator = Arfy::Generator.new
28
- generator.generate_migration_file ENV["NAME"], outdir
29
-
30
- puts 'not yet implemented'
30
+ file = generator.generate_migration_file ENV["NAME"], outdir
31
+ if file
32
+ puts "migration generated on: #{file}"
33
+ else
34
+ puts "FAIL. Migration not generated."
35
+ end
31
36
  end
32
37
  end
33
38
 
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: 0.1.3
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-20 00:00:00.000000000Z
12
+ date: 2011-09-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70118870495940 !ruby/object:Gem::Requirement
16
+ requirement: &70324994312800 !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: *70118870495940
24
+ version_requirements: *70324994312800
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: