Module: ActiveAdminAddons::InputMethods
- Included in:
- FilterInputMethods, InputBase, InputHtmlHelpers, SelectHelpers
- Defined in:
- lib/activeadmin_addons/support/input_helpers/input_methods.rb
Instance Method Summary collapse
- #association_name ⇒ Object
- #build_virtual_attr ⇒ Object
- #input_association_value ⇒ Object
- #input_related_items ⇒ Object
- #input_value ⇒ Object
- #method_model ⇒ Object
- #model_name ⇒ Object
- #object_class ⇒ Object
- #tableize_method ⇒ Object
- #translated_method ⇒ Object
- #url_from_method ⇒ Object
- #valid_method ⇒ Object
- #valid_object ⇒ Object
Instance Method Details
#association_name ⇒ Object
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_attr ⇒ Object
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_value ⇒ Object
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 |
#input_related_items ⇒ Object
37 38 39 40 41 |
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 37 def valid_object.send(tableize_method) rescue NoMethodError raise "no association called #{tableize_method} on #{model_name} model" end |
#input_value ⇒ Object
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_model ⇒ Object
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_name ⇒ Object
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_class ⇒ Object
19 20 21 |
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 19 def object_class valid_object.class end |
#tableize_method ⇒ Object
33 34 35 |
# File 'lib/activeadmin_addons/support/input_helpers/input_methods.rb', line 33 def tableize_method association_name.tableize end |
#translated_method ⇒ Object
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_method ⇒ Object
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_method ⇒ Object
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_object ⇒ Object
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 |