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:



23
24
25
# File 'lib/hotcocoa/mappings.rb', line 23

def mappings
  @mappings
end

Class Method Details

.load(framework) ⇒ Object

Load mappings for a given framework.

Parameters:

  • framework (String)


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

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)


57
58
59
60
61
# File 'lib/hotcocoa/mappings.rb', line 57

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.



27
28
29
# File 'lib/hotcocoa/mappings.rb', line 27

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