Class: Section
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Section
- Defined in:
- app/models/section.rb
Class Method Summary collapse
-
.model_names ⇒ Object
returns array of model names found in app/models/.
-
.valid_model_name?(name) ⇒ Boolean
check if given model name matches existing model.
Instance Method Summary collapse
-
#column_names ⇒ Object
returns array of valid column names of associated model.
- #detail_fields ⇒ Object
- #has_many_fields ⇒ Object
-
#model ⇒ Object
returns model corresponding to model_name, or nil if not found.
- #model_count ⇒ Object
- #name=(name_string) ⇒ Object
- #overview_fields ⇒ Object
Class Method Details
.model_names ⇒ Object
returns array of model names found in app/models/
18 19 20 |
# File 'app/models/section.rb', line 18 def self.model_names Dir.glob(Rails.root.to_s + '/app/models/*.rb').collect { |file| File.basename(file, '.*') } end |
.valid_model_name?(name) ⇒ Boolean
check if given model name matches existing model
23 24 25 |
# File 'app/models/section.rb', line 23 def self.valid_model_name?(name) !name.blank? && self.model_names.include?(name.downcase) end |
Instance Method Details
#column_names ⇒ Object
returns array of valid column names of associated model
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/section.rb', line 53 def column_names names = [] model.column_names.each do |col_name| # for paperclip attachments, add base name if col_name.match(/(.*)_file_name$/) names << $1 end names << col_name end return names end |
#detail_fields ⇒ Object
40 41 42 |
# File 'app/models/section.rb', line 40 def detail_fields self.fields.where(:display_type => 'detail') end |
#has_many_fields ⇒ Object
44 45 46 |
# File 'app/models/section.rb', line 44 def has_many_fields self.fields.where(:display_type => 'has_many') end |
#model ⇒ Object
returns model corresponding to model_name, or nil if not found
32 33 34 35 36 37 38 |
# File 'app/models/section.rb', line 32 def model begin return Object.const_get(model_name.singularize.camelize) rescue NameError return nil end end |
#model_count ⇒ Object
65 66 67 |
# File 'app/models/section.rb', line 65 def model_count model.count end |
#name=(name_string) ⇒ Object
27 28 29 |
# File 'app/models/section.rb', line 27 def name=(name_string) write_attribute(:name, name_string.gsub(/ /, "_").underscore) end |
#overview_fields ⇒ Object
48 49 50 |
# File 'app/models/section.rb', line 48 def overview_fields self.fields.where(:display_type => 'overview') end |