Module: Partitional::ClassMethods
- Defined in:
- lib/partitional.rb
Instance Method Summary collapse
- #partial_options ⇒ Object
- #partials ⇒ Object
- #partition(name, class_name: nil, mapping: {}, prefix: nil, validation: true) ⇒ Object
Instance Method Details
#partial_options ⇒ Object
13 14 15 |
# File 'lib/partitional.rb', line 13 def @partial_options ||= {} end |
#partials ⇒ Object
9 10 11 |
# File 'lib/partitional.rb', line 9 def partials @partials ||= [] end |
#partition(name, class_name: nil, mapping: {}, prefix: nil, validation: true) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/partitional.rb', line 17 def partition(name, class_name: nil, mapping: {}, prefix: nil, validation: true) name = name.to_s.to_sym partials.push(name) klass = (class_name || name).to_s.classify.constantize klass.attributes.each do |attr| mapping[attr] ||= "#{prefix ? "#{prefix}_" : ''}#{attr}" end [name] = { mapping: mapping } define_partial_accessor(name, klass, mapping) define_partial_validator(name, mapping) if validation end |