Module: Denormalized

Defined in:
lib/denormalized.rb,
lib/denormalized/core.rb,
lib/denormalized/version.rb

Defined Under Namespace

Modules: Core

Constant Summary collapse

VERSION =
'0.1.2'

Instance Method Summary collapse

Instance Method Details

#denormalized(*attributes) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/denormalized.rb', line 11

def denormalized(*attributes)
  options = attributes.extract_options!.dup

  if attributes.empty?
    raise ArgumentError, 'You need to supply at least one column'
  end
  if options.empty? || options[:tables]&.empty?
    raise ArgumentError, 'You need to supply at least one table'
  end

  class_attribute :denormalized_configuration

  self.denormalized_configuration = {
    columns: attributes,
    tables: options[:tables],
    columns_hash: Hash[attributes.map { |column| [column, true] }]
  }

  include Denormalized::Core unless denormalized?
end

#denormalized?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/denormalized.rb', line 7

def denormalized?
  included_modules.include?(Denormalized::Core)
end