Class: Monolens::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/monolens/registry.rb

Constant Summary collapse

LENS_NAME_RX =
/^[a-z]+\.[a-z][a-zA-Z\-_]+$/

Instance Method Summary collapse

Constructor Details

#initialize(registry = {}, default_namespace = 'core') ⇒ Registry

Returns a new instance of Registry.



5
6
7
8
# File 'lib/monolens/registry.rb', line 5

def initialize(registry = {}, default_namespace = 'core')
  @registry = registry
  @default_namespace = default_namespace
end

Instance Method Details

#define_namespace(name, impl_module) ⇒ Object



10
11
12
# File 'lib/monolens/registry.rb', line 10

def define_namespace(name, impl_module)
  @registry[name] = impl_module
end

#fork(default_namespace = 'self') ⇒ Object



33
34
35
# File 'lib/monolens/registry.rb', line 33

def fork(default_namespace = 'self')
  Registry.new(@registry.dup, default_namespace)
end

#lens(arg, registry = self) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/monolens/registry.rb', line 22

def lens(arg, registry = self)
  case arg
  when Lens               then arg
  when ::Array            then chain(arg, registry)
  when ::String, ::Symbol then leaf_lens(arg, registry)
  when ::Hash             then hash_lens(arg, registry)
  else
    raise Error, "No such lens #{arg} (#{arg.class})"
  end
end

#load_file(file, registry = self) ⇒ Object



14
15
16
# File 'lib/monolens/registry.rb', line 14

def load_file(file, registry = self)
  load_yaml(::File.read(file), registry)
end

#load_yaml(yaml, registry = self) ⇒ Object



18
19
20
# File 'lib/monolens/registry.rb', line 18

def load_yaml(yaml, registry = self)
  Monolens::File.new(YAML.safe_load(yaml), registry)
end