Created
September 22, 2017 01:40
-
-
Save Ji-Yuhang/1f0ecb3f24dc329ee33f2be18e34db76 to your computer and use it in GitHub Desktop.
rails mongo get all model names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'get Models'do | |
headers "Authentication-Token"=>{description: 'token',required: true } | |
end | |
get 'all_models' do | |
Rails.application.eager_load! if Rails.env.development? | |
models = Mongoid::Config.models | |
#fields.values.map{|f| o = f.options;{name: f.name,type: o[:type], kclass: o[:klass].to_s }} | |
present :models, models.map{|m|{model_name: m.to_s, relations: m.relations, field_names: m.fields.keys, fields: m.fields.values.map{|f| o = f.options;{name: f.name,type: o[:type].to_s, kclass: o[:klass].to_s }}}} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment