Module: AAN::Keeper

Extended by:
Keeper
Included in:
Keeper
Defined in:
lib/a_a_n/keeper.rb

Instance Method Summary collapse

Instance Method Details

#[](*args) ⇒ Object



19
20
21
# File 'lib/a_a_n/keeper.rb', line 19

def [](*args)
  (structure[args.first] ||= {})
end

#association(name, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/a_a_n/keeper.rb', line 28

def association(name, &block)
  sub_structure = block.call
  sub_structure.each do |element|
    if element.is_a? Hash
      element.symbolize_keys!
      element = element.to_a.flatten
    elsif
      element = [element.to_sym, "#{name}_#{element}".to_sym]
    end
    (AAN::Keeper[current_model][name] ||= []) << element
  end
end

#associations(model, &block) ⇒ Object



23
24
25
26
# File 'lib/a_a_n/keeper.rb', line 23

def associations model, &block
  @@current_model = model
  instance_eval &block
end

#nullify_aliased_methods_for(model, assoc) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/a_a_n/keeper.rb', line 7

def nullify_aliased_methods_for model, assoc
  aliased_methods = []
  AAN::Keeper.aliases_for(model, assoc).each do |aliased_method|
    aliased_methods << "@#{aliased_method} = nil"
  end
  aliased_methods.join("\n")
end

#structureObject



15
16
17
# File 'lib/a_a_n/keeper.rb', line 15

def structure
  @@structures ||= {}
end