nvim_conf 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +98 -0
- data/bin/nvim_conf +13 -0
- data/lib/nvim_conf/compiler_configurations/compiler_configuration.rb +12 -0
- data/lib/nvim_conf/compiler_configurations/manager.rb +74 -0
- data/lib/nvim_conf/configuration_builder.rb +37 -0
- data/lib/nvim_conf/core.rb +56 -0
- data/lib/nvim_conf/generators/code/mappings/lua.rb +54 -0
- data/lib/nvim_conf/generators/code/mappings/vim.rb +27 -0
- data/lib/nvim_conf/generators/code/plugins/packer.rb +76 -0
- data/lib/nvim_conf/generators/code/settings/lua.rb +53 -0
- data/lib/nvim_conf/generators/code/settings/vim.rb +47 -0
- data/lib/nvim_conf/generators/generator.rb +6 -0
- data/lib/nvim_conf/manager.rb +6 -0
- data/lib/nvim_conf/mappings/manager.rb +58 -0
- data/lib/nvim_conf/mappings/mapping.rb +13 -0
- data/lib/nvim_conf/plugins/manager.rb +41 -0
- data/lib/nvim_conf/plugins/plugin.rb +19 -0
- data/lib/nvim_conf/settings/manager.rb +43 -0
- data/lib/nvim_conf/settings/setting.rb +14 -0
- data/lib/nvim_conf/version.rb +5 -0
- data/lib/nvim_conf/writer.rb +87 -0
- data/lib/nvim_conf/writers/code/mappings.rb +39 -0
- data/lib/nvim_conf/writers/code/orchestrator.rb +55 -0
- data/lib/nvim_conf/writers/code/plugins.rb +86 -0
- data/lib/nvim_conf/writers/code/settings.rb +38 -0
- data/lib/nvim_conf/writers/documentation/mappings.rb +66 -0
- data/lib/nvim_conf/writers/documentation/orchestrator.rb +44 -0
- data/lib/nvim_conf/writers/documentation/settings.rb +71 -0
- data/lib/nvim_conf.rb +33 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b19da8fe7f4b4cd45d17e7c3d00866a6dbd2fc5d6c690826e3352b69ff227ec3
|
4
|
+
data.tar.gz: 13f5ce2072b6a61cf586d660cec6624407e3f6193f61b330fcd3b6779a625132
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fdd6c1532042741f60b69f0044d6889b0476c719b471be2c8777f9b20182dc7d7c3c36acdcac33aef109dd433258ed71015f776bac0d9878503b73ceaea0f480
|
7
|
+
data.tar.gz: 48580bebf403d43248b5d757a0b14936c376ee3658572da214a5ef967b78a6c68a9da41db028f7de5d4e801837da422689850b1471129e739bd37552732a70e6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Liberatys
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# NvimConf
|
2
|
+
|
3
|
+
A configuration manager for neovim that functions as an abstraction between your intentions and your configuration.
|
4
|
+
Functions in a way that prevents having to rewrite everything in order to change your plugin manager.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
NvimConf::Core.define do
|
10
|
+
plugins(:packer) do # add some plugins with any available plugin manager
|
11
|
+
plug("tpope/vim-fugitive")
|
12
|
+
plug("tpope/vim-surround")
|
13
|
+
end
|
14
|
+
|
15
|
+
configuration do # configurate the generation of code and documentation
|
16
|
+
output_folder '$HOME/.config/nvim'
|
17
|
+
code_output :lua # you want lua? you want vim? NO PROBLEM!
|
18
|
+
documented true
|
19
|
+
commented
|
20
|
+
end
|
21
|
+
|
22
|
+
settings do # define all your settings
|
23
|
+
set "tabstop"
|
24
|
+
unset "tabstop"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
### Output
|
30
|
+
#### Configuration
|
31
|
+
|
32
|
+
```lua
|
33
|
+
File: $HOME/.config/nvim/init.lua
|
34
|
+
|
35
|
+
return require('packer').startup(function()
|
36
|
+
use "tpope/vim-fugitive"
|
37
|
+
use "tpope/vim-surround"
|
38
|
+
end)
|
39
|
+
|
40
|
+
vim.o.tabstop = true
|
41
|
+
vim.o.tabstop = false
|
42
|
+
```
|
43
|
+
|
44
|
+
#### Documentation
|
45
|
+
|
46
|
+
```markdown
|
47
|
+
File: $HOME/.config/nvim/Init.md
|
48
|
+
|
49
|
+
# Configuration Documentation Vim - NvimConf
|
50
|
+
|
51
|
+
|
52
|
+
## Settings
|
53
|
+
- tabstop => true
|
54
|
+
- tabstop => false
|
55
|
+
```
|
56
|
+
## Why use NvimConf?
|
57
|
+
|
58
|
+
Neovim is changing fast! Every other week we can use an new package manager.
|
59
|
+
|
60
|
+
There is always a better version of your autocomplete plugin.
|
61
|
+
|
62
|
+
### **The goals of NvimConf are**
|
63
|
+
- Add automatic documentation to your configuration
|
64
|
+
- Decouple the configuration from the actual code needed to arrive at the configuration state
|
65
|
+
- Don't **version control** the configuration but manage the configuration schema
|
66
|
+
- No more file changes due to a change in package manager... just change the one line in your configuration generator
|
67
|
+
- Provide reproducible configuration
|
68
|
+
- Sharable and copiable configuration that allows everyone to configure their neovim
|
69
|
+
- Toolset to embed logic into your compiled configuration.
|
70
|
+
|
71
|
+
## Features to come
|
72
|
+
|
73
|
+
- Generators
|
74
|
+
- More plugin managers
|
75
|
+
- Auto Completion
|
76
|
+
- Linters
|
77
|
+
- Configuraton optimization
|
78
|
+
- Remove duplicate Plugins
|
79
|
+
- Remove overwriting settings
|
80
|
+
- Param Checker
|
81
|
+
- Validate the settings parameters
|
82
|
+
- Check generated settings for functionality
|
83
|
+
- Custom embeeded Functions
|
84
|
+
- Split Configuraton into multiple files
|
85
|
+
- Render optimization by reducing the generation set
|
86
|
+
- Comment your configuration automatically
|
87
|
+
- Extend documentation generation
|
88
|
+
- Add plugin documentation
|
89
|
+
- Options for styling / spacing
|
90
|
+
- Meta information for your configuration
|
91
|
+
- Version
|
92
|
+
- Author-Name
|
93
|
+
- Generation Date
|
94
|
+
- Generation Architecture (Macos / Linux)
|
95
|
+
|
96
|
+
## Examples
|
97
|
+
|
98
|
+
You can find more examples of configurations here: [example folder](./examples)
|
data/bin/nvim_conf
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'nvim_conf'
|
6
|
+
|
7
|
+
if ARGV[0]
|
8
|
+
puts "Running nvim_conf for #{ARGV[0]}"
|
9
|
+
|
10
|
+
load(Pathname.new(ARGV[0]).expand_path)
|
11
|
+
else
|
12
|
+
puts 'No file path to run nvim_conf was given'
|
13
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "nvim_conf/compiler_configurations/compiler_configuration"
|
2
|
+
|
3
|
+
module NvimConf
|
4
|
+
module CompilerConfigurations
|
5
|
+
class Manager < NvimConf::Manager
|
6
|
+
attr_reader :configurations
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@configurations = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def store?
|
13
|
+
@configurations.any?
|
14
|
+
end
|
15
|
+
|
16
|
+
def output_folder(path)
|
17
|
+
store_configuration(
|
18
|
+
:output_folder,
|
19
|
+
path
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def write(acceptance = true)
|
24
|
+
store_configuration(
|
25
|
+
:write,
|
26
|
+
acceptance
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def code_output(language)
|
31
|
+
store_configuration(
|
32
|
+
:code_output,
|
33
|
+
language.to_s
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def mono_file(acceptance = true)
|
38
|
+
store_configuration(
|
39
|
+
:mono_file,
|
40
|
+
acceptance
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def documented(formats)
|
45
|
+
store_configuration(
|
46
|
+
:documented,
|
47
|
+
formats
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def commented(acceptance = true)
|
52
|
+
store_configuration(
|
53
|
+
:commented,
|
54
|
+
acceptance
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def store_configuration(name, value)
|
61
|
+
@configurations << build_configuration(
|
62
|
+
name, value
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_configuration(name, value)
|
67
|
+
CompilerConfiguration.new(
|
68
|
+
name,
|
69
|
+
value
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "nvim_conf/compiler_configurations/manager"
|
2
|
+
|
3
|
+
module NvimConf
|
4
|
+
class ConfigurationBuilder
|
5
|
+
CONFIGURATION_MANAGER = NvimConf::CompilerConfigurations::Manager
|
6
|
+
|
7
|
+
def initialize(managers)
|
8
|
+
@managers = managers
|
9
|
+
@configuration = default_configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def build_configuration
|
13
|
+
@managers.select { |manager| manager.instance_of?(CONFIGURATION_MANAGER) }.each do |manager|
|
14
|
+
manager.configurations.each do |configuration|
|
15
|
+
@configuration[configuration.name] = configuration.value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
@configuration[:format] ||= @configuration[:schema] == :nvim ? :lua : :vim
|
20
|
+
@configuration
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def default_configuration
|
26
|
+
{
|
27
|
+
output_folder: "$HOME/.config/nvim",
|
28
|
+
code_output: :lua,
|
29
|
+
write: false,
|
30
|
+
mono_file: true,
|
31
|
+
documented: false,
|
32
|
+
commented: true,
|
33
|
+
schema: :nvim
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module NvimConf
|
2
|
+
class Core
|
3
|
+
def self.define(&block)
|
4
|
+
new.instance_eval(&block)
|
5
|
+
|
6
|
+
NvimConf::Writer.new(
|
7
|
+
NvimConf.managers
|
8
|
+
).write
|
9
|
+
end
|
10
|
+
|
11
|
+
def plugins(name, bootstraped: false, &block)
|
12
|
+
store_manager(
|
13
|
+
evaluate_for_manager(
|
14
|
+
Plugins::Manager.new(name, bootstraped: bootstraped),
|
15
|
+
&block
|
16
|
+
)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def settings(&block)
|
21
|
+
store_manager(evaluate_for_manager(
|
22
|
+
Settings::Manager.new,
|
23
|
+
&block
|
24
|
+
))
|
25
|
+
end
|
26
|
+
|
27
|
+
def mappings(namespace = nil, &block)
|
28
|
+
store_manager(evaluate_for_manager(
|
29
|
+
Mappings::Manager.new(namespace),
|
30
|
+
&block
|
31
|
+
))
|
32
|
+
end
|
33
|
+
|
34
|
+
def configuration(&block)
|
35
|
+
store_manager(evaluate_for_manager(
|
36
|
+
CompilerConfigurations::Manager.new,
|
37
|
+
&block
|
38
|
+
))
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def evaluate_for_manager(manager, &block)
|
44
|
+
manager.instance_eval(&block)
|
45
|
+
manager
|
46
|
+
end
|
47
|
+
|
48
|
+
def store_manager(manager)
|
49
|
+
return unless manager.store?
|
50
|
+
|
51
|
+
NvimConf.managers.push(
|
52
|
+
manager
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module NvimConf
|
2
|
+
module Generators
|
3
|
+
module Mappings
|
4
|
+
module Code
|
5
|
+
class Lua
|
6
|
+
MODE_MAPPING = {
|
7
|
+
"map" => "",
|
8
|
+
"nmap" => "n",
|
9
|
+
"vmap" => "v",
|
10
|
+
"smap" => "s",
|
11
|
+
"xmap" => "x",
|
12
|
+
"omap" => "o",
|
13
|
+
"map!" => "!",
|
14
|
+
"imap" => "i",
|
15
|
+
"lmap" => "l",
|
16
|
+
"cmap" => "c",
|
17
|
+
"tmap" => "t"
|
18
|
+
}
|
19
|
+
|
20
|
+
BASE_METHOD = "vim.api.nvim_set_keymap"
|
21
|
+
|
22
|
+
def initialize(mapping)
|
23
|
+
@mapping = mapping
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate
|
27
|
+
[
|
28
|
+
BASE_METHOD,
|
29
|
+
"(",
|
30
|
+
argument_list,
|
31
|
+
")"
|
32
|
+
].join
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def argument_list
|
38
|
+
[
|
39
|
+
MODE_MAPPING[@mapping.operator.to_s],
|
40
|
+
@mapping.binding,
|
41
|
+
@mapping.action
|
42
|
+
].map do |value|
|
43
|
+
[
|
44
|
+
"\'",
|
45
|
+
value,
|
46
|
+
"\'"
|
47
|
+
].join
|
48
|
+
end.join(", ")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module NvimConf
|
2
|
+
module Generators
|
3
|
+
module Mappings
|
4
|
+
module Code
|
5
|
+
class Vim
|
6
|
+
def initialize(mapping)
|
7
|
+
@mapping = mapping
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate
|
11
|
+
[
|
12
|
+
vim_method,
|
13
|
+
@mapping.binding,
|
14
|
+
@mapping.action
|
15
|
+
].join(" ")
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def vim_method
|
21
|
+
@mapping.operator.to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module NvimConf
|
2
|
+
module Generators
|
3
|
+
module Plugins
|
4
|
+
module Code
|
5
|
+
class Packer
|
6
|
+
COMMAND_PREFIX = :use
|
7
|
+
|
8
|
+
COMMAND_ALIAS = {
|
9
|
+
file_types: :ft
|
10
|
+
}
|
11
|
+
|
12
|
+
def initialize(plugin)
|
13
|
+
@plugin = plugin
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate
|
17
|
+
generated_call = [
|
18
|
+
COMMAND_PREFIX,
|
19
|
+
command_call
|
20
|
+
].join(" ")
|
21
|
+
|
22
|
+
args? ? "{#{generated_call}}" : generated_call
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def command_call
|
28
|
+
[
|
29
|
+
plugin_name,
|
30
|
+
*command_arguments
|
31
|
+
].compact.join(", ")
|
32
|
+
end
|
33
|
+
|
34
|
+
def plugin_name
|
35
|
+
"'#{@plugin.name}'"
|
36
|
+
end
|
37
|
+
|
38
|
+
def command_arguments
|
39
|
+
[
|
40
|
+
:as,
|
41
|
+
:opt,
|
42
|
+
:file_types,
|
43
|
+
:branch,
|
44
|
+
:run,
|
45
|
+
:cmd
|
46
|
+
].map do |argument|
|
47
|
+
next if @plugin.send(argument).nil?
|
48
|
+
|
49
|
+
[
|
50
|
+
COMMAND_ALIAS[argument] || argument,
|
51
|
+
escape_value(@plugin.send(argument))
|
52
|
+
].join(" = ")
|
53
|
+
end.compact
|
54
|
+
end
|
55
|
+
|
56
|
+
def escape_value(value)
|
57
|
+
return value unless value.is_a?(String)
|
58
|
+
|
59
|
+
"'#{value}'"
|
60
|
+
end
|
61
|
+
|
62
|
+
def args?
|
63
|
+
[
|
64
|
+
@plugin.as,
|
65
|
+
@plugin.opt,
|
66
|
+
@plugin.branch,
|
67
|
+
@plugin.file_types,
|
68
|
+
@plugin.cmd,
|
69
|
+
@plugin.run
|
70
|
+
].any? { |argument| !argument.nil? }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module NvimConf
|
2
|
+
module Generators
|
3
|
+
module Settings
|
4
|
+
module Code
|
5
|
+
class Lua
|
6
|
+
VIM_PREFIX = :vim
|
7
|
+
|
8
|
+
SETTING_NAMESPACES = {
|
9
|
+
global: "o",
|
10
|
+
buffer: "bo"
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(setting)
|
14
|
+
@setting = setting
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate
|
18
|
+
[
|
19
|
+
call_signature,
|
20
|
+
escaped_value
|
21
|
+
].join(" = ")
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def call_signature
|
27
|
+
[
|
28
|
+
VIM_PREFIX,
|
29
|
+
SETTING_NAMESPACES[@setting.scope] || SETTING_NAMESPACES[:global],
|
30
|
+
@setting.key
|
31
|
+
].join(".")
|
32
|
+
end
|
33
|
+
|
34
|
+
def escaped_value
|
35
|
+
return fallback_to_truthy_on_nil(@setting.value) unless @setting.value.is_a?(String)
|
36
|
+
|
37
|
+
[
|
38
|
+
'"',
|
39
|
+
@setting.value,
|
40
|
+
'"'
|
41
|
+
].join
|
42
|
+
end
|
43
|
+
|
44
|
+
def fallback_to_truthy_on_nil(value)
|
45
|
+
return value unless value.nil?
|
46
|
+
|
47
|
+
@setting.operation == :set
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module NvimConf
|
2
|
+
module Generators
|
3
|
+
module Settings
|
4
|
+
module Code
|
5
|
+
class Vim
|
6
|
+
SET_OPERATION = :set
|
7
|
+
|
8
|
+
def initialize(setting)
|
9
|
+
@setting = setting
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate
|
13
|
+
[
|
14
|
+
call_identifier,
|
15
|
+
escaped_value
|
16
|
+
].compact.join(" = ")
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def call_identifier
|
22
|
+
[
|
23
|
+
SET_OPERATION,
|
24
|
+
negated_operator!
|
25
|
+
].join(" ")
|
26
|
+
end
|
27
|
+
|
28
|
+
def negated_operator!
|
29
|
+
return @setting.key if @setting.operation == :set
|
30
|
+
|
31
|
+
"#{@setting.key}!"
|
32
|
+
end
|
33
|
+
|
34
|
+
def escaped_value
|
35
|
+
return @setting.value unless @setting.value.is_a?(String)
|
36
|
+
|
37
|
+
[
|
38
|
+
'"',
|
39
|
+
@setting.value,
|
40
|
+
'"'
|
41
|
+
].join
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "nvim_conf/mappings/mapping"
|
2
|
+
# TODO: Refactor error messages
|
3
|
+
module NvimConf
|
4
|
+
module Mappings
|
5
|
+
class Manager < NvimConf::Manager
|
6
|
+
AVAILABLE_METHODS = %w[map map! nmap vmap imap cmap smap xmap omap lmap]
|
7
|
+
attr_reader :mappings
|
8
|
+
|
9
|
+
def initialize(namespace)
|
10
|
+
@mappings = []
|
11
|
+
@namespace = namespace&.to_s
|
12
|
+
|
13
|
+
validate!
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate!
|
17
|
+
return if @namespace.nil? || @namespace.empty?
|
18
|
+
|
19
|
+
raise "Invalid namespace given for <mappings>: #{@namespace}" unless AVAILABLE_METHODS.include?(@namespace)
|
20
|
+
end
|
21
|
+
|
22
|
+
def store?
|
23
|
+
@mappings.any?
|
24
|
+
end
|
25
|
+
|
26
|
+
AVAILABLE_METHODS.each do |operator|
|
27
|
+
define_method(operator) do |binding, action|
|
28
|
+
store_mapping(
|
29
|
+
operator, binding, action
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def new(binding, action)
|
35
|
+
raise "No namespace was given for <mappings>" unless @namespace
|
36
|
+
raise "No namespace was given for <mappings>" if @namespace.empty?
|
37
|
+
|
38
|
+
store_mapping(
|
39
|
+
@namespace, binding, action
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :m, :new
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def store_mapping(operator, binding, action)
|
48
|
+
@mappings << build_mapping(
|
49
|
+
operator, binding, action
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_mapping(operator, binding, action)
|
54
|
+
Mapping.new(operator, binding, action)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|