Class: SeedReaper::ConfigEvaluator

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ConfigEvaluator

Returns a new instance of ConfigEvaluator.



5
6
7
# File 'lib/seed_reaper/config_evaluator.rb', line 5

def initialize(config)
  @config = config
end

Instance Method Details

#belongs_to_schema(instance) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/seed_reaper/config_evaluator.rb', line 17

def belongs_to_schema(instance)
  return nil unless schema
  return schema.select { |k| instance._reflections[k.to_s].belongs_to? } if schema.is_a?(Hash)
  return schema.select do |c|
    if c.is_a?(Hash)
      instance._reflections[c.first[0].to_s].belongs_to?
    else
      instance._reflections[c.to_s].belongs_to?
    end
  end if schema.is_a?(Array)
  return schema if instance._reflections[schema.to_s].belongs_to?
end

#non_belongs_to_schema(instance) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/seed_reaper/config_evaluator.rb', line 30

def non_belongs_to_schema(instance)
  return nil unless schema
  return schema.reject { |k| instance._reflections[k.to_s].belongs_to? } if schema.is_a?(Hash)
  return schema.reject do |c|
    if c.is_a?(Hash)
      instance._reflections[c.first[0].to_s].belongs_to?
    else
      instance._reflections[c.to_s].belongs_to?
    end
  end if schema.is_a?(Array)
  return schema unless instance._reflections[schema.to_s].belongs_to?
end

#schemaObject



9
10
11
12
13
14
15
# File 'lib/seed_reaper/config_evaluator.rb', line 9

def schema
  return nil unless @config
  return @config.reject { |k| k == :meta } if @config.is_a?(Hash)
  return @config.reject { |c| c.is_a?(Hash) && c.has_key?(:meta) } if @config.is_a?(Array)

  @config
end