class Cartograph::Map

Public Class Methods

new() click to toggle source
# File lib/cartograph/map.rb, line 5
def initialize
  @scope_mutex = Mutex.new
  @current_scopes = []
  @cache = nil
  @cache_calculator = nil
  @mapping = nil
end

Public Instance Methods

==(other) click to toggle source
# File lib/cartograph/map.rb, line 87
def ==(other)
  methods = %i(properties root_keys mapping cache cache_key)
  methods.inject(true) do |current_value, method|
    break unless current_value
    send(method) == other.send(method)
  end
end
cache(object = nil) click to toggle source
# File lib/cartograph/map.rb, line 52
def cache(object = nil)
  @cache = object unless object.nil?
  @cache.nil? ? Cartograph.default_cache : @cache
end
cache_key(&calculator) click to toggle source
# File lib/cartograph/map.rb, line 57
def cache_key(&calculator)
  @cache_calculator = calculator if block_given?
  @cache_calculator.nil? ? Cartograph.default_cache_key : @cache_calculator
end
dup() click to toggle source
# File lib/cartograph/map.rb, line 70
def dup
  Cartograph::Map.new.tap do |map|
    self.properties.each do |property|
      map.properties << property.dup
    end

    map.mapping self.mapping

    self.root_keys.each do |rk|
      map.root_keys << rk
    end

    map.cache self.cache
    map.cache_key(&self.cache_key) if self.cache_key
  end
end
mapping(klass = nil) click to toggle source
# File lib/cartograph/map.rb, line 43
def mapping(klass = nil)
  @mapping = klass if klass
  @mapping
end
properties() click to toggle source
# File lib/cartograph/map.rb, line 25
def properties
  @properties ||= PropertyCollection.new
end
property(*args, &block) click to toggle source
# File lib/cartograph/map.rb, line 13
def property(*args, &block)
  options = args.last.is_a?(Hash) ? args.pop : {}

  # Append scopes if we're currently mapping in a scoped block
  options[:scopes] ||= []
  options[:scopes] += Array(@current_scopes)

  args.each do |prop|
    properties << Property.new(prop, options, &block)
  end
end
root_key(options) click to toggle source
# File lib/cartograph/map.rb, line 48
def root_key(options)
  root_keys << RootKey.new(options)
end
root_key_for(scope, type) click to toggle source
# File lib/cartograph/map.rb, line 62
def root_key_for(scope, type)
  return unless %i(singular plural).include?(type)

  if (root_key = root_keys.select {|rk| rk.scopes.include?(scope) }[0])
    root_key.send(type)
  end
end
root_keys() click to toggle source
# File lib/cartograph/map.rb, line 39
def root_keys
  @root_keys ||= []
end
scoped(*scopes, &block) click to toggle source
# File lib/cartograph/map.rb, line 29
def scoped(*scopes, &block)
  @scope_mutex.synchronize do
    @current_scopes = scopes

    instance_eval(&block) if block_given?

    @current_scopes = nil
  end
end