Module: RailsAdmin::Adapters::ActiveRecord
- Defined in:
- lib/rails_admin/adapters/active_record.rb,
lib/rails_admin/adapters/active_record/abstract_object.rb
Defined Under Namespace
Classes: AbstractObject
Constant Summary collapse
- DISABLED_COLUMN_TYPES =
[:tsvector, :blob, :binary, :spatial, :hstore, :geometry]
- DISABLED_COLUMN_MATCHERS =
[/_array$/]
Instance Method Summary collapse
- #adapter_supports_joins? ⇒ Boolean
- #all(options = {}, scope = nil) ⇒ Object
- #ar_adapter ⇒ Object
- #associations ⇒ Object
- #count(options = {}, scope = nil) ⇒ Object
- #destroy(objects) ⇒ Object
- #embedded? ⇒ Boolean
- #encoding ⇒ Object
- #first(options = {}, scope = nil) ⇒ Object
- #get(id) ⇒ Object
- #like_operator ⇒ Object
- #new(params = {}) ⇒ Object
- #primary_key ⇒ Object
- #properties ⇒ Object
- #scoped ⇒ Object
- #table_name ⇒ Object
Instance Method Details
#adapter_supports_joins? ⇒ Boolean
110 111 112 |
# File 'lib/rails_admin/adapters/active_record.rb', line 110 def adapter_supports_joins? true end |
#all(options = {}, scope = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rails_admin/adapters/active_record.rb', line 38 def all( = {}, scope = nil) scope ||= self.scoped scope = scope.includes([:include]) if [:include] scope = scope.limit([:limit]) if [:limit] scope = scope.where(model.primary_key => [:bulk_ids]) if [:bulk_ids] scope = scope.where(query_conditions([:query])) if [:query] scope = scope.where(filter_conditions([:filters])) if [:filters] if [:page] && [:per] scope = scope.send(Kaminari.config.page_method_name, [:page]).per([:per]) end scope = scope.reorder("#{[:sort]} #{[:sort_reverse] ? 'asc' : 'desc'}") if [:sort] scope end |
#ar_adapter ⇒ Object
10 11 12 |
# File 'lib/rails_admin/adapters/active_record.rb', line 10 def ar_adapter Rails.configuration.database_configuration[Rails.env]['adapter'] end |
#associations ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rails_admin/adapters/active_record.rb', line 64 def associations model.reflect_on_all_associations.map do |association| { :name => association.name.to_sym, :pretty_name => association.name.to_s.tr('_', ' ').capitalize, :type => association.macro, :model_proc => Proc.new { association_model_lookup(association) }, :primary_key_proc => Proc.new { association_primary_key_lookup(association) }, :foreign_key => association_foreign_key_lookup(association), :foreign_type => association_foreign_type_lookup(association), :as => association_as_lookup(association), :polymorphic => association_polymorphic_lookup(association), :inverse_of => association_inverse_of_lookup(association), :read_only => association_read_only_lookup(association), :nested_form => (association) } end end |
#count(options = {}, scope = nil) ⇒ Object
52 53 54 |
# File 'lib/rails_admin/adapters/active_record.rb', line 52 def count( = {}, scope = nil) all(.merge({:limit => false, :page => false}), scope).count end |
#destroy(objects) ⇒ Object
56 57 58 |
# File 'lib/rails_admin/adapters/active_record.rb', line 56 def destroy(objects) Array.wrap(objects).each &:destroy end |
#embedded? ⇒ Boolean
106 107 108 |
# File 'lib/rails_admin/adapters/active_record.rb', line 106 def false end |
#encoding ⇒ Object
102 103 104 |
# File 'lib/rails_admin/adapters/active_record.rb', line 102 def encoding Rails.configuration.database_configuration[Rails.env]['encoding'] end |
#first(options = {}, scope = nil) ⇒ Object
34 35 36 |
# File 'lib/rails_admin/adapters/active_record.rb', line 34 def first( = {}, scope = nil) all(, scope).first end |
#get(id) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/rails_admin/adapters/active_record.rb', line 22 def get(id) if object = model.where(model.primary_key => id).first AbstractObject.new object else nil end end |
#like_operator ⇒ Object
14 15 16 |
# File 'lib/rails_admin/adapters/active_record.rb', line 14 def like_operator ar_adapter == "postgresql" ? 'ILIKE' : 'LIKE' end |
#new(params = {}) ⇒ Object
18 19 20 |
# File 'lib/rails_admin/adapters/active_record.rb', line 18 def new(params = {}) AbstractObject.new(model.new(params)) end |
#primary_key ⇒ Object
60 61 62 |
# File 'lib/rails_admin/adapters/active_record.rb', line 60 def primary_key model.primary_key end |
#properties ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rails_admin/adapters/active_record.rb', line 83 def properties columns = model.columns.reject do |c| c.type.blank? || DISABLED_COLUMN_TYPES.include?(c.type.to_sym) || DISABLED_COLUMN_MATCHERS.any? {|matcher| matcher.match(c.type.to_s)} end columns.map do |property| { :name => property.name.to_sym, :pretty_name => property.name.to_s.tr('_', ' ').capitalize, :length => property.limit, :nullable? => property.null, :serial? => property.primary, }.merge(type_lookup(property)) end end |
#scoped ⇒ Object
30 31 32 |
# File 'lib/rails_admin/adapters/active_record.rb', line 30 def scoped model.scoped end |
#table_name ⇒ Object
98 99 100 |
# File 'lib/rails_admin/adapters/active_record.rb', line 98 def table_name model.table_name end |