Class: Kablam::KablamRecord
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Kablam::KablamRecord
- Defined in:
- lib/kablam/kablam_record.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.choices(field, locale) ⇒ Object
56 57 58 59 60 |
# File 'lib/kablam/kablam_record.rb', line 56 def self.choices(field, locale) c_set = self.form_choices[field] return false if c_set.blank? c_set.map{|choice| {value: choice[:value], label: (choice[:label][locale.to_s] || "CHOICE TRANSLATION NOT FOUND! PLEASE CONTACT STAFF!")}} end |
.field_set ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kablam/kablam_record.rb', line 22 def self.field_set field_types = { input: [], text: [], hidden: [], select: [], checkbox_array: [], checkbox_boolean: [], multi_inputs: [], file_upload: [], exclude: ["id", "created_at", "updated_at", "destroyed_at"] } user_fields = set_fields user_fields[:exclude] += field_types[:exclude] if user_fields[:exclude].present? field_types.merge user_fields.select { |k| field_types.keys.include? k } end |
.fields ⇒ Object
18 19 20 |
# File 'lib/kablam/kablam_record.rb', line 18 def self.fields result = self.attribute_names - ["id", "created_at", "updated_at"] end |
.prep_form_field ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kablam/kablam_record.rb', line 40 def self.prep_form_field # This method will prepare hash of hashes # for each data-field w/ the form input type. # ex: date, radio, select, etc. obj = self.new hashy = {} fields_array = self.fields fields_array.each do |k| hashy[k] = obj.column_for_attribute(k).type hashy[k] = :input if [:string, :float, :integer].include? hashy[k] hashy[k] = :checkbox_boolean if [:boolean].include? hashy[k] self.field_set.keys.each{|type| hashy[k] = type if self.field_set[type].include?(k)} end hashy end |
Instance Method Details
#identifier ⇒ Object
14 15 16 |
# File 'lib/kablam/kablam_record.rb', line 14 def identifier send(self.class.fields.first) end |
#standard_hash ⇒ Object
9 10 11 12 |
# File 'lib/kablam/kablam_record.rb', line 9 def standard_hash serializable_hash.except("created_at", "updated_at").reject{|k,v|v.blank?} end |
#undoable? ⇒ Boolean
5 6 7 |
# File 'lib/kablam/kablam_record.rb', line 5 def undoable? attributes.include?("destroyed_at") end |