Module: Monolens
- Defined in:
- lib/monolens.rb,
lib/monolens/str.rb,
lib/monolens/core.rb,
lib/monolens/file.rb,
lib/monolens/lens.rb,
lib/monolens/skip.rb,
lib/monolens/array.rb,
lib/monolens/error.rb,
lib/monolens/coerce.rb,
lib/monolens/object.rb,
lib/monolens/command.rb,
lib/monolens/version.rb,
lib/monolens/core/dig.rb,
lib/monolens/array/map.rb,
lib/monolens/skip/null.rb,
lib/monolens/str/split.rb,
lib/monolens/str/strip.rb,
lib/monolens/array/join.rb,
lib/monolens/core/chain.rb,
lib/monolens/str/upcase.rb,
lib/monolens/coerce/date.rb,
lib/monolens/object/keys.rb,
lib/monolens/core/mapping.rb,
lib/monolens/lens/options.rb,
lib/monolens/str/downcase.rb,
lib/monolens/array/compact.rb,
lib/monolens/coerce/string.rb,
lib/monolens/error_handler.rb,
lib/monolens/lens/location.rb,
lib/monolens/object/extend.rb,
lib/monolens/object/rename.rb,
lib/monolens/object/select.rb,
lib/monolens/object/values.rb,
lib/monolens/coerce/integer.rb,
lib/monolens/coerce/date_time.rb,
lib/monolens/object/transform.rb,
lib/monolens/lens/fetch_support.rb
Defined Under Namespace
Modules: Array, Coerce, Core, Lens, Object, Skip, Str, Version
Classes: Command, Error, ErrorHandler, File, LensError
Constant Summary
collapse
- NAMESPACES =
{ }
- VERSION =
"#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
Class Method Summary
collapse
Class Method Details
.chain(lenses) ⇒ Object
42
43
44
|
# File 'lib/monolens.rb', line 42
def chain(lenses)
Core::Chain.new(lenses.map{|l| lens(l) })
end
|
.define_namespace(name, impl_module) ⇒ Object
11
12
13
|
# File 'lib/monolens.rb', line 11
def define_namespace(name, impl_module)
NAMESPACES[name] = impl_module
end
|
.factor_lens(namespace_name, lens_name, options) ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/monolens.rb', line 71
def factor_lens(namespace_name, lens_name, options)
namespace = NAMESPACES[namespace_name]
if namespace&.private_method_defined?(lens_name, false)
namespace.send(lens_name, options)
else
raise Error, "No such lens #{[namespace_name, lens_name].join('.')}"
end
end
|
.file_lens(arg) ⇒ Object
47
48
49
|
# File 'lib/monolens.rb', line 47
def file_lens(arg)
File.new(arg)
end
|
.hash_lens(arg) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/monolens.rb', line 57
def hash_lens(arg)
return file_lens(arg) if arg['version'] || arg[:version]
raise "Invalid lens #{arg}" unless arg.size == 1
name, options = arg.to_a.first
namespace_name, lens_name = if name =~ /^[a-z]+\.[a-z]+$/
name.to_s.split('.')
else
['core', name]
end
factor_lens(namespace_name, lens_name, options)
end
|
.leaf_lens(arg) ⇒ Object
51
52
53
54
|
# File 'lib/monolens.rb', line 51
def leaf_lens(arg)
namespace_name, lens_name = arg.to_s.split('.')
factor_lens(namespace_name, lens_name, {})
end
|
.lens(arg) ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/monolens.rb', line 31
def lens(arg)
case arg
when Lens then arg
when ::Array then chain(arg)
when ::String, ::Symbol then leaf_lens(arg)
when ::Hash then hash_lens(arg)
else
raise Error, "No such lens #{arg} (#{arg.class})"
end
end
|
.load_file(file) ⇒ Object
23
24
25
|
# File 'lib/monolens.rb', line 23
def load_file(file)
Monolens::File.new(YAML.safe_load(::File.read(file)))
end
|
.load_yaml(yaml) ⇒ Object
27
28
29
|
# File 'lib/monolens.rb', line 27
def load_yaml(yaml)
Monolens::File.new(YAML.safe_load(yaml))
end
|