Class: AdminData::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/admin_data/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.


97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/admin_data/configuration.rb', line 97

def initialize
  @number_of_records_per_page =  50
  @is_allowed_to_view         = nil
  @is_allowed_to_update       = nil
  @is_allowed_to_view_feed    = nil
  @find_conditions            = {}
  @drop_down_for_associations = true
  @columns_order              = {}
  @column_headers             = {}
  @column_settings            = {}
  @adapter_name               =  ActiveRecord::Base.connection.adapter_name
  @ignore_column_limit        = false
end

Instance Attribute Details

#adapter_nameObject (readonly)

TODO explain why it is needed


88
89
90
# File 'lib/admin_data/configuration.rb', line 88

def adapter_name
  @adapter_name
end

#column_headersObject

Tell AdminData how to name a column in a listing Example:

config.column_headers = => {:id => 'ID'


95
96
97
# File 'lib/admin_data/configuration.rb', line 95

def column_headers
  @column_headers
end

#column_settingsObject

Tell AdminData how to display the value for a column

AdminData.config do |config|
  proc = lambda {|model| model.send(:data).inspect}
  config.column_settings = {'City' => {:data => proc } }
end

62
63
64
# File 'lib/admin_data/configuration.rb', line 62

def column_settings
  @column_settings
end

#columns_orderObject

Tell AdminData how to order the columns for a model.

AdminData.config do |config|
  config.column_order = {'City' => [:id, :title, :body, :published_at, :author_name]}
end

70
71
72
# File 'lib/admin_data/configuration.rb', line 70

def columns_order
  @columns_order
end

By default this value is true . Set this value to false if you do not want all the belongs_to ids to be populated. If set to false then instead of a dropdown user will get a text field where the id can be entered. It matters only while editing or creating a new record.


18
19
20
# File 'lib/admin_data/configuration.rb', line 18

def drop_down_for_associations
  @drop_down_for_associations
end

#feed_authentication_passwordObject

For feed authentication a combination of user_id and password is used. This attribute sets the password .


38
39
40
# File 'lib/admin_data/configuration.rb', line 38

def feed_authentication_password
  @feed_authentication_password
end

#feed_authentication_user_idObject

For feed authentication a combination of user_id and password is used. This attribute sets the user_id .


34
35
36
# File 'lib/admin_data/configuration.rb', line 34

def feed_authentication_user_id
  @feed_authentication_user_id
end

#find_conditionsObject

Tell AdminData to not to use id for models like given below.

class City < ActiveRecord::Base

def to_param
  self.permanent_name
end

end

AdminData.config do |config|
  proc = lambda {|params| {:conditions => ["permanent_name = ?", params[:id] ] } }
  config.find_conditions = {'City' => proc }
end

53
54
55
# File 'lib/admin_data/configuration.rb', line 53

def find_conditions
  @find_conditions
end

#ignore_column_limitObject

Default value is false . Set this value to true if you want admin_data to ignored the column_limit returned by ActiveRecord .


11
12
13
# File 'lib/admin_data/configuration.rb', line 11

def ignore_column_limit
  @ignore_column_limit
end

#is_allowed_to_updateObject


77
78
79
80
# File 'lib/admin_data/configuration.rb', line 77

def is_allowed_to_update
  return lambda {|controller| return true } if Rails.env.development?
  @is_allowed_to_update || lambda {|_| nil }
end

#is_allowed_to_viewObject


72
73
74
75
# File 'lib/admin_data/configuration.rb', line 72

def is_allowed_to_view
  return lambda {|controller| return true } if Rails.env.development?
  @is_allowed_to_view || lambda {|_| nil }
end

#is_allowed_to_view_feedObject


82
83
84
85
# File 'lib/admin_data/configuration.rb', line 82

def is_allowed_to_view_feed
  return lambda {|controller| return true } if Rails.env.development?
  @is_allowed_to_view_feed || lambda {|_| nil }
end

#number_of_records_per_pageObject

Number of recores displayed while listing records


6
7
8
# File 'lib/admin_data/configuration.rb', line 6

def number_of_records_per_page
  @number_of_records_per_page
end

Instance Method Details

#display_assoc?(class_name) ⇒ Boolean

Returns:

  • (Boolean)

111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/admin_data/configuration.rb', line 111

def display_assoc?( class_name )
  case @drop_down_for_associations
    when Hash
      return @drop_down_for_associations[ class_name ]
    when TrueClass, FalseClass
      return @drop_down_for_associations
    when NilClass 
      return false
    else
      raise "Configuration Error. #{@drop_down_for_associations} " \
            "must be true, false or a Hash."
  end
end