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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67dc98e6bc35ac25f7d6d5766d5ca8584b5f2794
4
- data.tar.gz: 9b2f02ccd15291bf2ef523f7fb90c5083db0c523
3
+ metadata.gz: bae622dc39af8def28fd7f52393d1514ef97a9c4
4
+ data.tar.gz: ebe05cba1a33fe98c26eec02cb0357da6f287f24
5
5
  SHA512:
6
- metadata.gz: 4e3b71ac72e6895e2178fca9a2904b3acfc4613fca8d812103b79d532b721238ee6f75ef820865a709276aa34fad274775c0c0d3a9a67b45eebbfee17155d21b
7
- data.tar.gz: 96837c4b693a119b6aeafc4d41accf2e790a66c25ee2e50820d7569ac26a5dd96f7cc1882e64e71509d41e957dc433ee296f066a916d569b9d705e3c67df8f52
6
+ metadata.gz: 3c19843b87308806aa1e2fef9d4bdc9bd0d6fdbca9ae0b693e245a9d3698c486c2b2ee4e623f06f9f2b042ed447d51003e68cc8ca67534b694dfdb040f7cf946
7
+ data.tar.gz: 590422f7a642fccc62ec54a6b94c96eb51d0099892c61ffe53780410fc6fa4776206e3ded9a22651d86fc3c31bb96f70cddcde5e55013216983cb211ca46bd69
data/README.md CHANGED
@@ -1,3 +1,48 @@
1
- = ModelDiscovery
1
+ # ModelDiscovery [![Gem Version](https://badge.fury.io/rb/model_discovery.png)](http://badge.fury.io/rb/model_discovery)
2
2
 
3
- This project rocks and uses MIT-LICENSE.
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
- puts "Gem name: #{gem.name}"
9
- spec = Gem::Specification.find_by_name gem.name
10
- discover spec.gem_dir
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
@@ -1,3 +1,3 @@
1
1
  module ModelDiscovery
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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-29 00:00:00.000000000 Z
11
+ date: 2014-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails