class Fabrication::Transform

Public Class Methods

apply_to(schematic, attributes_hash) click to toggle source
# File lib/fabrication/transform.rb, line 8
def apply_to(schematic, attributes_hash)
  Fabrication.manager.load_definitions if Fabrication.manager.empty?
  attributes_hash.inject({}) { |h, (k, v)| h.update(k => instance.apply_transform(schematic, k, v)) }
end
clear_all() click to toggle source
# File lib/fabrication/transform.rb, line 13
def clear_all
  instance.transforms.clear
  instance.overrides.clear
end
define(attribute, transform) click to toggle source
# File lib/fabrication/transform.rb, line 18
def define(attribute, transform)
  instance.transforms[attribute] = transform
end
only_for(schematic, attribute, transform) click to toggle source
# File lib/fabrication/transform.rb, line 22
def only_for(schematic, attribute, transform)
  instance.overrides[schematic] = (instance.overrides[schematic] || {}).merge!(attribute => transform)
end

Public Instance Methods

apply_transform(schematic, attribute, value) click to toggle source
# File lib/fabrication/transform.rb, line 31
def apply_transform(schematic, attribute, value)
  overrides.fetch(schematic, transforms)[attribute].call(value)
end
overrides() click to toggle source
# File lib/fabrication/transform.rb, line 27
def overrides
  @overrides ||= {}
end
transforms() click to toggle source
# File lib/fabrication/transform.rb, line 35
def transforms
  @transforms ||= Hash.new(->(value) { value })
end