Module: Unico::CustomData::ClassMethods

Defined in:
lib/custom_data.rb

Instance Method Summary collapse

Instance Method Details

#custom_attributesObject



33
34
35
36
37
# File 'lib/custom_data.rb', line 33

def custom_attributes
  return unless custom_data

  custom_data.map(&:method_name)
end

#custom_dataObject



39
40
41
42
43
44
45
46
# File 'lib/custom_data.rb', line 39

def custom_data
  class_name = name.underscore
  current_state = ::Prefecture.last.state_acronym

  Customization.new(current_state, class_name).data
rescue
  {}
end

#reload_custom_dataObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/custom_data.rb', line 6

def reload_custom_data
  return unless custom_data

  custom_data.each do |data|
    define_method(data.method_name) do
      custom_data[data.method_name]
    end

    if data.select?
      define_method("#{data.method_name}_humanize") do
        data.humanized_option(custom_data[data.method_name])
      end
    end

    define_method("#{data.method_name}=") do |value|
      self.custom_data = custom_data.merge(data.method_name => value)
    end

    next unless data.modal?
    define_method(data.normalized_data) do
      if send(data.method_name).present?
        data.modal_entity.classify.constantize.send(:find, send(data.method_name))
      end
    end
  end
end