model_discovery 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -2
- data/lib/model_discovery/discovery.rb +6 -4
- data/lib/model_discovery/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bae622dc39af8def28fd7f52393d1514ef97a9c4
|
4
|
+
data.tar.gz: ebe05cba1a33fe98c26eec02cb0357da6f287f24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c19843b87308806aa1e2fef9d4bdc9bd0d6fdbca9ae0b693e245a9d3698c486c2b2ee4e623f06f9f2b042ed447d51003e68cc8ca67534b694dfdb040f7cf946
|
7
|
+
data.tar.gz: 590422f7a642fccc62ec54a6b94c96eb51d0099892c61ffe53780410fc6fa4776206e3ded9a22651d86fc3c31bb96f70cddcde5e55013216983cb211ca46bd69
|
data/README.md
CHANGED
@@ -1,3 +1,48 @@
|
|
1
|
-
|
1
|
+
# ModelDiscovery [![Gem Version](https://badge.fury.io/rb/model_discovery.png)](http://badge.fury.io/rb/model_discovery)
|
2
2
|
|
3
|
-
|
3
|
+
ModelDiscovery is a simple yet flexible and fast solution to model discovery problem in Ruby on Rails applications. Detecting applications model in a Rails application is a bit hard because of [autoload](http://api.rubyonrails.org/classes/ActiveSupport/Autoload.html) convention, specially when you use set of gems which add their own models to your application.
|
4
|
+
|
5
|
+
ModelDiscovery provides a solution to this problem without loading models in runtime. If you're familiar with [Django](https://www.djangoproject.com) framework, you can think ok ModelDiscovery as something like **ContentType** application in Django.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'model_discovery'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install model_discovery
|
19
|
+
|
20
|
+
Then add this line to your `db/seeds.rb` file:
|
21
|
+
```ruby
|
22
|
+
ModelDiscovery::Engine.load_seed
|
23
|
+
```
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
ModelDiscovery will add a model to your application which will contains all the models class name. So you can use active record's query to fetch model names like:
|
27
|
+
```ruby
|
28
|
+
# Fetch all models class names
|
29
|
+
models = ApplicationModels.all
|
30
|
+
# => ["User", "Group", "SomeGem::ModelExample"]
|
31
|
+
|
32
|
+
# Access to actual class of a model
|
33
|
+
model_class = models[0].constantize
|
34
|
+
# => "User"
|
35
|
+
|
36
|
+
# It's like User.all
|
37
|
+
model_class.all
|
38
|
+
```
|
39
|
+
It's simple isn't it ?
|
40
|
+
## Bugs
|
41
|
+
If you find any bug or have any issue using this gem I'll be happy to know. Please file an issue in [Issue Tracker](https://github.com/Yellowen/model_discovery/issues)
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
@@ -1,13 +1,15 @@
|
|
1
1
|
module ModelDiscovery
|
2
2
|
def self.build_table_list
|
3
3
|
# Get all gem by requiring them
|
4
|
-
all_gems = Bundler.require
|
4
|
+
all_gems = Bundler.require()
|
5
5
|
|
6
6
|
# Discover all model files in gem files and load them
|
7
7
|
all_gems.each do |gem|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if gem.groups.include? Rails.env.to_sym or gem.groups.include? :default
|
9
|
+
puts "Gem name: #{gem.name}"
|
10
|
+
spec = Gem::Specification.find_by_name gem.name
|
11
|
+
discover spec.gem_dir
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
# Discover models in current rails app and load them
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_discovery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sameer Rahmani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01
|
11
|
+
date: 2014-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|