Class: React::NativeLibrary

Inherits:
Object show all
Defined in:
lib/react/native_library.rb

Class Method Summary collapse

Class Method Details

.const_missing(name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/react/native_library.rb', line 11

def self.const_missing(name)
  if renames_and_exclusions.has_key? name
    if native_name = renames_and_exclusions[name]
      native_name
    else
      super
    end
  else
    libraries.each do |library|
      native_name = "#{library}.#{name}"
      native_component = `eval(#{native_name})` rescue nil
      React::API.import_native_component(name, native_component) and return name if native_component and `native_component != undefined`
    end
    name
  end
end

.exclude(*exclude_list) ⇒ Object



49
50
51
# File 'lib/react/native_library.rb', line 49

def self.exclude(*exclude_list)
  renames_and_exclusions.merge(Hash[exclude_list.map {|k| [k, nil]}])
end

.imports(library) ⇒ Object



41
42
43
# File 'lib/react/native_library.rb', line 41

def self.imports(library)
  libraries << library
end

.librariesObject



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

def self.libraries
  @libraries ||= []
end

.method_missing(n, *args, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/react/native_library.rb', line 28

def self.method_missing(n, *args, &block)
  name = n
  if name =~ /_as_node$/
    node_only = true
    name = name.gsub(/_as_node$/, "")
  end
  unless name = const_get(name)
    return super
  end
  React::RenderingContext.build_or_render(node_only, name, *args, &block)
rescue
end

.rename(rename_list = {}) ⇒ Object



45
46
47
# File 'lib/react/native_library.rb', line 45

def self.rename(rename_list={})
  renames_and_exclusions.merge!(rename_list.invert)
end

.renames_and_exclusionsObject



3
4
5
# File 'lib/react/native_library.rb', line 3

def self.renames_and_exclusions
  @renames_and_exclusions ||= {}
end