Module: ActiveAdminAddons::InputMethods

Included in:
FilterInputMethods, InputBase, InputHtmlHelpers, SelectHelpers
Defined in:
lib/activeadmin_addons/support/input_helpers/input_methods.rb

Instance Method Summary collapse

Instance Method Details

#association_nameObject



23
24
25
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 23

def association_name
  valid_method.to_s.singularize.chomp("_id")
end

#build_virtual_attrObject



66
67
68
69
70
71
72
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 66

def build_virtual_attr
  attribute_name = "virtual_#{valid_method}_attr"
  fail "#{attribute_name} is already defined" if valid_object.respond_to?(attribute_name)

  valid_object.singleton_class.send(:attr_accessor, attribute_name)
  attribute_name
end

#input_association_valueObject



47
48
49
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 47

def input_association_value
  @input_association_value ||= valid_object.send(association_name)
end


37
38
39
40
41
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 37

def input_related_items
  valid_object.send(tableize_method)
rescue NoMethodError
  raise "no association called #{tableize_method} on #{model_name} model"
end

#input_valueObject



43
44
45
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 43

def input_value
  @input_value ||= valid_object.send(valid_method)
end

#method_modelObject



27
28
29
30
31
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 27

def method_model
  @options[:method_model] ||
    object_class.reflect_on_association(association_name).try(:klass) ||
    association_name.classify.constantize
end

#model_nameObject



3
4
5
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 3

def model_name
  valid_object.class.to_s.underscore.tr('/', '_')
end

#object_classObject



19
20
21
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 19

def object_class
  valid_object.class
end

#tableize_methodObject



33
34
35
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 33

def tableize_method
  association_name.tableize
end

#translated_methodObject



51
52
53
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 51

def translated_method
  valid_object.class.human_attribute_name(valid_method)
end

#url_from_methodObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 55

def url_from_method
  url = ["/"]

  if ActiveAdmin.application.default_namespace.present?
    url << "#{ActiveAdmin.application.default_namespace}/"
  end

  url << tableize_method
  url.join("")
end

#valid_methodObject



7
8
9
10
11
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 7

def valid_method
  raise "invalid method given" if method.blank?

  method
end

#valid_objectObject



13
14
15
16
17
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 13

def valid_object
  raise "blank object given" if @object.blank?

  @object
end