lithium-activerecord 0.0.1

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: 119df7cbbbd26bd14c5db15f176f65a4b00808a0
4
+ data.tar.gz: be940d91e3b71cd9ee91a320915085879edc745c
5
+ SHA512:
6
+ metadata.gz: 24e932dacf5583c1bfc895469758bb3643ad3bfe3daad1bdf5905147af9789379cf673278b7a21869241ba62a1d2873dd20620d279efbaa2dcb0b17e3ec4b321
7
+ data.tar.gz: a572d5d6ceccfe58718ed698217344a7f478a5dcaa09a53b7d452ba939b04447d49ec066bf8e1426968594e7075ac9969c242b38d03bddd81ca9dbe660c88c3c
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lithium-activerecord.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Lithium ActiveRecord Extension
2
+
3
+ Extends Lithium with extension methods and Rake tasks for dealing with an SQL database using the ActiveRecord ORM.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'lithium-activerecord'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install lithium-activerecord
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/lithium-activerecord/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,29 @@
1
+ require "active_support/string_inquirer"
2
+
3
+ module Rails
4
+ extend self
5
+
6
+ def root
7
+ Pathname.new(Rake.application.original_dir)
8
+ end
9
+
10
+ def env
11
+ ActiveSupport::StringInquirer.new(ENV["RACK_ENV"] || "development")
12
+ end
13
+
14
+ def application
15
+ seed_loader = Object.new
16
+ seed_loader.instance_eval do
17
+ def load_seed
18
+ load "db/seeds.rb"
19
+ end
20
+ end
21
+ seed_loader
22
+ end
23
+ end
24
+
25
+ Rake::Task["db:seed"].enhance(["db:load_config"])
26
+ Rake::Task["db:load_config"].clear
27
+
28
+ Rake::Task.define_task("db:environment")
29
+ Rake::Task.define_task("db:rails_env")
@@ -0,0 +1,21 @@
1
+ seed_loader = Class.new do
2
+ def load_seed
3
+ load "#{ActiveRecord::Tasks::DatabaseTasks.db_dir}/seeds.rb"
4
+ end
5
+ end
6
+
7
+ ActiveRecord::Tasks::DatabaseTasks.tap do |config|
8
+ config.root = Rake.application.original_dir
9
+ config.env = ENV["RACK_ENV"] || "development"
10
+ config.db_dir = "db"
11
+ config.migrations_paths = ["db/migrate"]
12
+ config.fixtures_path = "test/fixtures"
13
+ config.seed_loader = seed_loader.new
14
+ config.database_configuration = ActiveRecord::Base.configurations
15
+ end
16
+
17
+ Rake::Task["db:seed"].enhance(["db:load_config"])
18
+ Rake::Task["db:load_config"].clear
19
+
20
+ Rake::Task.define_task("db:environment")
21
+ Rake::Task["db:test:deprecated"].clear if Rake::Task.task_defined?("db:test:deprecated")
@@ -0,0 +1,6 @@
1
+ load "active_record/railties/databases.rake"
2
+ require "lithium/activerecord/rake/activerecord_#{ActiveRecord::VERSION::MAJOR}"
3
+
4
+ load "lithium/activerecord/tasks.rake"
5
+
6
+ ActiveRecord::Base.logger = nil
@@ -0,0 +1,39 @@
1
+ require "active_support/core_ext/string/strip"
2
+ require "pathname"
3
+ require "fileutils"
4
+
5
+ namespace :db do
6
+ desc "Create a migration (parameters: NAME, VERSION)"
7
+ task :create_migration do
8
+ unless ENV["NAME"]
9
+ puts "No NAME specified. Example usage: `rake db:create_migration NAME=create_users`"
10
+ exit
11
+ end
12
+
13
+ name = ENV["NAME"]
14
+ version = ENV["VERSION"] || Time.now.utc.strftime("%Y%m%d%H%M%S")
15
+
16
+ ActiveRecord::Migrator.migrations_paths.each do |directory|
17
+ next unless File.exist?(directory)
18
+ migration_files = Pathname(directory).children
19
+ if duplicate = migration_files.find { |path| path.basename.to_s.include?(name) }
20
+ puts "Another migration is already named \"#{name}\": #{duplicate}."
21
+ exit
22
+ end
23
+ end
24
+
25
+ filename = "#{version}_#{name}.rb"
26
+ dirname = ActiveRecord::Migrator.migrations_path
27
+ path = File.join(dirname, filename)
28
+
29
+ FileUtils.mkdir_p(dirname)
30
+ File.write path, <<-MIGRATION.strip_heredoc
31
+ class #{name.camelize} < ActiveRecord::Migration
32
+ def change
33
+ end
34
+ end
35
+ MIGRATION
36
+
37
+ puts path
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module Lithium
2
+ module Activerecord
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require "lithium/activerecord/version"
2
+
3
+ require 'active_record'
4
+ require 'active_support/core_ext/hash/keys'
5
+
6
+ require 'logger'
7
+ require 'pathname'
8
+ require 'yaml'
9
+ require 'erb'
10
+
11
+ module Lithium
12
+ module ActiveRecord
13
+ def self.registered app
14
+ settings = Lithium::Base.settings
15
+ file = "#{Dir.pwd}/config/database.yml" if File.exist?("#{Dir.pwd}/config/database.yml")
16
+ path = File.join(root, file) if Pathname(file).relative? and root
17
+ hash = YAML.load(File.read(file))
18
+ ::ActiveRecord::Base.establish_connection(hash[settings[:environment]])
19
+ app.before do
20
+ app.before { ::ActiveRecord::Base.verify_active_connections! if ::ActiveRecord::Base.respond_to?(:verify_active_connections!) }
21
+ app.after { ::ActiveRecord::Base.clear_active_connections! }
22
+ end
23
+
24
+ Dir[File.join(Dir.pwd, "models", "*.rb")].each do |file|
25
+ require file
26
+ end
27
+ app.helpers self
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lithium-activerecord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sedat CIFTCI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: lithium
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ description: Lithium Active Record
70
+ email:
71
+ - me@sedat.us
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - README.md
78
+ - Rakefile
79
+ - lib/lithium/activerecord.rb
80
+ - lib/lithium/activerecord/rake.rb
81
+ - lib/lithium/activerecord/rake/activerecord_3.rb
82
+ - lib/lithium/activerecord/rake/activerecord_4.rb
83
+ - lib/lithium/activerecord/tasks.rake
84
+ - lib/lithium/activerecord/version.rb
85
+ homepage: ''
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.2.2
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Lithium Active Record
109
+ test_files: []