Module: Mappy

Defined in:
lib/mappy.rb,
lib/mappy/version.rb,
lib/mappy/resolver.rb,
lib/mappy/map_store.rb,
lib/mappy/exceptions.rb,
lib/mappy/configuration.rb,
lib/mappy/target_builder_factory.rb

Defined Under Namespace

Classes: InvalidTargetBuilder, MapNotFound

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



7
8
9
# File 'lib/mappy.rb', line 7

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|config| ... } ⇒ Object

Registers a collection of maps.

Examples:

Mappy.configure do |config|
  config.register(source: 'book', target: 'orcid/work', legend: [:name, :title])
end

Yield Parameters:

  • config (Configuration)

See Also:

  • Railtie


34
35
36
# File 'lib/mappy.rb', line 34

def configure(&block)
  yield(configuration)
end

.finalize!Object

Deprecated.


60
61
# File 'lib/mappy.rb', line 60

def finalize!
end

.map(source, options = {}) ⇒ Object

Converts the source object to an instance of the options.

Examples:

Mappy.configure do |config|
  config.register(source: 'book', target: 'orcid/work', legend: [:name, :title])
end
book = Book.new(title: 'Hello World')
orcid_work = Mappy.map(book, target: 'orcid/work')

assert_equal orcid_work.title, book.name

Parameters:

  • source (Object)

    :source - the instance of a class that you are mapping from

  • options (Hash) (defaults to: {})

Returns:

  • (Object)

    an instance of the :target that has been instantiated by mapping the :source object

See Also:



55
56
57
# File 'lib/mappy.rb', line 55

def map(source, options = {})
  configuration.map(source, options)
end

.reset!Object

Because sometimes, when you are testing things, you might want a new configuration. :nodoc:



66
67
68
# File 'lib/mappy.rb', line 66

def reset!
  self.configuration = Configuration.new
end

.to_type(object) ⇒ String

Determines the object’s Mappy type

Parameters:

  • object (Object)

    the source object

Returns:

  • (String)

    the Mappy type which should be used in configuring Mappy

See Also:



20
21
22
23
# File 'lib/mappy.rb', line 20

def to_type(object)
  return object.to_mappy_type if object.respond_to?(:to_mappy_type)
  object.class.to_s.underscore
end