class ActiveShepherd::Method

Attributes

aggregate[R]
associations[R]
attributes[R]

Public Class Methods

inherited(base) click to toggle source
# File lib/active_shepherd/method.rb, line 5
def self.inherited(base)
  # If you're looking for magic, you've come to the right place
  return unless base.name.match /Methods::/
  apply_or_query, state_or_changes = base.name.demodulize.underscore.split('_', 2)
  method_name = "#{apply_or_query}_#{state_or_changes}"
  action_proc = ->(*args) { new(*args).send(method_name) }
  base.singleton_class.send :define_method, method_name, &action_proc
end
new(*args) click to toggle source
# File lib/active_shepherd/method.rb, line 16
def initialize(*args)
  @aggregate    = args.shift
  @associations = {}
  @attributes   = {}

  setup *args
end

Public Instance Methods

recurse(model, foreign_key) click to toggle source
# File lib/active_shepherd/method.rb, line 24
def recurse(model, foreign_key)
  Aggregate.new model, foreign_key
end
traverse!() click to toggle source
# File lib/active_shepherd/method.rb, line 28
def traverse!
  Traversal.new(
    self,
    attributes: attributes,
    associations: associations,
  ).traverse
end