Module: MonkeyForms::Form::ClassMethods
- Defined in:
- lib/monkey_forms.rb
Instance Attribute Summary collapse
-
#form_storage ⇒ Object
readonly
Returns the value of attribute form_storage.
Instance Method Summary collapse
- #attributes ⇒ Object
- #custom_attributes(*attrs) ⇒ Object
- #form_attributes(*attrs) ⇒ Object
- #form_name(name) ⇒ Object
- #human_attribute_name(name, *options) ⇒ Object
-
#model_name ⇒ Object
Compatibility with ActiveModel::Naming.
- #set_form_attribute_human_names(options) ⇒ Object
- #set_form_storage(storage_object) ⇒ Object
Instance Attribute Details
#form_storage ⇒ Object (readonly)
Returns the value of attribute form_storage.
83 84 85 |
# File 'lib/monkey_forms.rb', line 83 def form_storage @form_storage end |
Instance Method Details
#attributes ⇒ Object
85 86 87 |
# File 'lib/monkey_forms.rb', line 85 def attributes @attributes ||= {} end |
#custom_attributes(*attrs) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/monkey_forms.rb', line 140 def custom_attributes *attrs attrs.each do |attr| instance_eval do attr_reader attr end end end |
#form_attributes(*attrs) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/monkey_forms.rb', line 125 def form_attributes *attrs @attributes ||= [] attrs.each do |attr| @attributes << attr # Defines public method define_method attr do @attributes[attr.to_s] end define_method "#{attr}=" do |value| @attributes[attr.to_s] = value end end end |
#form_name(name) ⇒ Object
107 108 109 |
# File 'lib/monkey_forms.rb', line 107 def form_name name @_form_name = name end |
#human_attribute_name(name, *options) ⇒ Object
120 121 122 123 |
# File 'lib/monkey_forms.rb', line 120 def human_attribute_name name, * @_form_attribute_names ||= {} @_form_attribute_names[name] || super end |
#model_name ⇒ Object
Compatibility with ActiveModel::Naming
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/monkey_forms.rb', line 90 def model_name if !defined?(@_model_name) # EWWWW @_model_name = (@_form_name.try(:to_s) || superclass.instance_variable_get(:@_form_name).try(:to_s) || name.underscore).try(:underscore) %w( singular human i18n_key partial_path plural ).each do |method| @_model_name.class_eval do define_method method do self end end end end @_model_name end |
#set_form_attribute_human_names(options) ⇒ Object
115 116 117 118 |
# File 'lib/monkey_forms.rb', line 115 def set_form_attribute_human_names @_form_attribute_names ||= {} @_form_attribute_names.merge!() end |
#set_form_storage(storage_object) ⇒ Object
111 112 113 |
# File 'lib/monkey_forms.rb', line 111 def set_form_storage storage_object @form_storage = storage_object end |