Class: MagicReport::Report::Builder::HasOne

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_report/report/builder/has_one.rb

Direct Known Subclasses

HasMany

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report, name, options, extension) ⇒ HasOne

Returns a new instance of HasOne.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/magic_report/report/builder/has_one.rb', line 13

def initialize(report, name, options, extension)
  @report = report
  @name = name
  @options = options
  @extension = extension
  @prefix = I18n.t!("#{report.i18n_scope}.#{report.i18n_key}.#{name}_relation")

  unless options[:class]
    klass = ::MagicReport::Report.clone
    klass.define_singleton_method(:name) { "#{report.name}/#{name}" }
    klass.class_eval(&extension)

    options[:class] = klass
  end
end

Instance Attribute Details

#extensionObject (readonly)

Returns the value of attribute extension.



11
12
13
# File 'lib/magic_report/report/builder/has_one.rb', line 11

def extension
  @extension
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/magic_report/report/builder/has_one.rb', line 11

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/magic_report/report/builder/has_one.rb', line 11

def options
  @options
end

#prefixObject (readonly)

Returns the value of attribute prefix.



11
12
13
# File 'lib/magic_report/report/builder/has_one.rb', line 11

def prefix
  @prefix
end

#reportObject (readonly)

Returns the value of attribute report.



11
12
13
# File 'lib/magic_report/report/builder/has_one.rb', line 11

def report
  @report
end

Class Method Details

.build(report, name, options, &extension) ⇒ Object



7
8
9
# File 'lib/magic_report/report/builder/has_one.rb', line 7

def self.build(report, name, options, &extension)
  new(report, name, options, extension)
end

Instance Method Details

#build_rowObject



43
44
45
# File 'lib/magic_report/report/builder/has_one.rb', line 43

def build_row
  options[:class].build_row(prefix)
end

#process(model) ⇒ Object



29
30
31
32
33
34
# File 'lib/magic_report/report/builder/has_one.rb', line 29

def process(model)
  relation = extract_relation(model)

  # Refactor here values method call
  options[:class].new(relation).values
end

#process_rows(model, row) ⇒ Object



36
37
38
39
40
41
# File 'lib/magic_report/report/builder/has_one.rb', line 36

def process_rows(model, row)
  relation = extract_relation(model)

  # Refactor here values method call
  options[:class].new(relation, row).rows
end