Module: HotCocoa::Mappings

Defined in:
lib/hotcocoa/mappings.rb

Defined Under Namespace

Modules: TargetActionConvenience Classes: Mapper

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.mappingsHash{Symbol=>HotCocoa::Mappings::Mapper} (readonly)

The cache of mappers for available mappings.

Returns:



21
22
23
# File 'lib/hotcocoa/mappings.rb', line 21

def mappings
  @mappings
end

Class Method Details

.load(framework) ⇒ Object

Load mappings for a given framework.

Parameters:

  • framework (String)


33
34
35
36
37
38
39
40
41
# File 'lib/hotcocoa/mappings.rb', line 33

def load framework
  framework = framework.downcase
  dir       = File.join(@path, framework)
  if Dir.exists? dir
    Dir.glob(File.join(dir, '**/*.rb')).each do |mapping|
      require mapping.chomp! '.rb'
    end
  end
end

.map(name, &block) ⇒ Object

Create a new mapping by registering mapped_name as a builder method for mapped_class.

Examples:


HotCocoa::Mappings.map( window: NSWindow ) do
  # define your mapping
end

Parameters:

  • mapped_name (Symbol)
  • mapped_class (Class)


55
56
57
58
59
# File 'lib/hotcocoa/mappings.rb', line 55

def map name, &block
  mapped_name, mapped_class = name.first
  mappings[mapped_name] =
    HotCocoa::Mappings::Mapper.map_instances_of mapped_class, mapped_name, &block
end

.reloadObject

Load mappings for every loaded framework.



25
26
27
# File 'lib/hotcocoa/mappings.rb', line 25

def reload
  $LOADED_FRAMEWORKS.each do |framework| load framework end
end