Class: Mochigome::ReportFocus

Inherits:
Object
  • Object
show all
Defined in:
lib/model_extensions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, settings) ⇒ ReportFocus

Returns a new instance of ReportFocus.



158
159
160
161
162
163
# File 'lib/model_extensions.rb', line 158

def initialize(owner, settings)
  @owner = owner
  @name_proc = settings.options[:name] || lambda{|obj| obj.name}
  @type_name = settings.options[:type_name] || owner.class.human_name
  @fieldsets = settings.options[:fieldsets] || {}
end

Instance Attribute Details

#type_nameObject (readonly)

Returns the value of attribute type_name.



156
157
158
# File 'lib/model_extensions.rb', line 156

def type_name
  @type_name
end

Instance Method Details

#field_data(fieldset_names = nil) ⇒ Object



169
170
171
172
173
174
175
176
177
# File 'lib/model_extensions.rb', line 169

def field_data(fieldset_names = nil)
  fieldset_names ||= [:default]
  h = ActiveSupport::OrderedHash.new
  field_descs = fieldset_names.map{|n|@fieldsets[n]}.compact.flatten(1).uniq
  field_descs.each do |field|
    h[field[:name]] = field[:value_func].call(@owner)
  end
  h
end

#nameObject



165
166
167
# File 'lib/model_extensions.rb', line 165

def name
  @name_proc.call(@owner)
end