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
- #dont_strip_form_attributes! ⇒ 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
- #strip_attributes? ⇒ Boolean
Instance Attribute Details
#form_storage ⇒ Object (readonly)
Returns the value of attribute form_storage.
94 95 96 |
# File 'lib/monkey_forms.rb', line 94 def form_storage @form_storage end |
Instance Method Details
#attributes ⇒ Object
96 97 98 |
# File 'lib/monkey_forms.rb', line 96 def attributes @attributes ||= {} end |
#custom_attributes(*attrs) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/monkey_forms.rb', line 160 def custom_attributes *attrs attrs.each do |attr| instance_eval do attr_reader attr end end end |
#dont_strip_form_attributes! ⇒ Object
126 127 128 |
# File 'lib/monkey_forms.rb', line 126 def dont_strip_form_attributes! @_strip_attributes = false end |
#form_attributes(*attrs) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/monkey_forms.rb', line 145 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
118 119 120 |
# File 'lib/monkey_forms.rb', line 118 def form_name name @_form_name = name end |
#human_attribute_name(name, *options) ⇒ Object
140 141 142 143 |
# File 'lib/monkey_forms.rb', line 140 def human_attribute_name name, * @_form_attribute_names ||= {} @_form_attribute_names[name] || super end |
#model_name ⇒ Object
Compatibility with ActiveModel::Naming
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/monkey_forms.rb', line 101 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 param_key).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
135 136 137 138 |
# File 'lib/monkey_forms.rb', line 135 def set_form_attribute_human_names @_form_attribute_names ||= {} @_form_attribute_names.merge!() end |
#set_form_storage(storage_object) ⇒ Object
122 123 124 |
# File 'lib/monkey_forms.rb', line 122 def set_form_storage storage_object @form_storage = storage_object end |
#strip_attributes? ⇒ Boolean
130 131 132 133 |
# File 'lib/monkey_forms.rb', line 130 def strip_attributes? return true if !defined?(@_strip_attributes) return @_strip_attributes end |