rubanok 0.1.1 → 0.4.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 +4 -4
- data/CHANGELOG.md +59 -0
- data/LICENSE.txt +1 -1
- data/README.md +231 -33
- data/lib/rubanok.rb +8 -4
- data/lib/rubanok/dsl/mapping.rb +22 -5
- data/lib/rubanok/dsl/matching.rb +40 -16
- data/lib/rubanok/processor.rb +144 -0
- data/lib/rubanok/rails/controller.rb +59 -14
- data/lib/rubanok/railtie.rb +6 -0
- data/lib/rubanok/rspec.rb +25 -11
- data/lib/rubanok/rule.rb +32 -24
- data/lib/rubanok/version.rb +1 -1
- data/sig/rubanok.rbs +6 -0
- data/sig/rubanok/dsl/mapping.rbs +18 -0
- data/sig/rubanok/dsl/matching.rbs +44 -0
- data/sig/rubanok/processor.rbs +53 -0
- data/sig/rubanok/rule.rbs +29 -0
- data/sig/rubanok/version.rbs +3 -0
- data/sig/typeprof.rb +25 -0
- metadata +27 -58
- data/.gitignore +0 -12
- data/.rspec +0 -3
- data/.rubocop.yml +0 -63
- data/.travis.yml +0 -24
- data/Gemfile +0 -13
- data/Gemfile.local +0 -2
- data/Rakefile +0 -10
- data/bin/console +0 -8
- data/bin/setup +0 -8
- data/gemfiles/rails42.gemfile +0 -6
- data/gemfiles/rails52.gemfile +0 -6
- data/gemfiles/railsmaster.gemfile +0 -5
- data/lib/rubanok/ext/symbolize_keys.rb +0 -13
- data/lib/rubanok/plane.rb +0 -92
- data/rubanok.gemspec +0 -35
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- standard/cop/semantic_blocks
|
3
|
-
- rubocop-rspec
|
4
|
-
|
5
|
-
inherit_gem:
|
6
|
-
standard: config/base.yml
|
7
|
-
|
8
|
-
AllCops:
|
9
|
-
Exclude:
|
10
|
-
- 'bin/*'
|
11
|
-
- 'tmp/**/*'
|
12
|
-
- 'Gemfile'
|
13
|
-
- 'vendor/**/*'
|
14
|
-
- 'gemfiles/**/*'
|
15
|
-
DisplayCopNames: true
|
16
|
-
|
17
|
-
Standard/SemanticBlocks:
|
18
|
-
Enabled: false
|
19
|
-
|
20
|
-
Style/TrailingCommaInArrayLiteral:
|
21
|
-
EnforcedStyleForMultiline: no_comma
|
22
|
-
|
23
|
-
Style/TrailingCommaInHashLiteral:
|
24
|
-
EnforcedStyleForMultiline: no_comma
|
25
|
-
|
26
|
-
Style/FrozenStringLiteralComment:
|
27
|
-
Enabled: true
|
28
|
-
|
29
|
-
RSpec/Focus:
|
30
|
-
Enabled: true
|
31
|
-
|
32
|
-
RSpec/EmptyExampleGroup:
|
33
|
-
Enabled: true
|
34
|
-
|
35
|
-
RSpec/EmptyLineAfterExampleGroup:
|
36
|
-
Enabled: true
|
37
|
-
|
38
|
-
RSpec/EmptyLineAfterFinalLet:
|
39
|
-
Enabled: true
|
40
|
-
|
41
|
-
RSpec/EmptyLineAfterHook:
|
42
|
-
Enabled: true
|
43
|
-
|
44
|
-
RSpec/EmptyLineAfterSubject:
|
45
|
-
Enabled: true
|
46
|
-
|
47
|
-
RSpec/HooksBeforeExamples:
|
48
|
-
Enabled: true
|
49
|
-
|
50
|
-
RSpec/ImplicitExpect:
|
51
|
-
Enabled: true
|
52
|
-
|
53
|
-
RSpec/IteratedExpectation:
|
54
|
-
Enabled: true
|
55
|
-
|
56
|
-
RSpec/LetBeforeExamples:
|
57
|
-
Enabled: true
|
58
|
-
|
59
|
-
RSpec/MissingExampleGroupArgument:
|
60
|
-
Enabled: true
|
61
|
-
|
62
|
-
RSpec/ReceiveCounts:
|
63
|
-
Enabled: true
|
data/.travis.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.6.0
|
5
|
-
|
6
|
-
notifications:
|
7
|
-
email: false
|
8
|
-
|
9
|
-
before_install:
|
10
|
-
- gem update --system
|
11
|
-
- gem install bundler
|
12
|
-
|
13
|
-
matrix:
|
14
|
-
fast_finish: true
|
15
|
-
include:
|
16
|
-
- rvm: ruby-head
|
17
|
-
gemfile: gemfiles/railsmaster.gemfile
|
18
|
-
- rvm: 2.6.0
|
19
|
-
gemfile: gemfiles/rails52.gemfile
|
20
|
-
- rvm: 2.5.1
|
21
|
-
gemfile: gemfiles/rails42.gemfile
|
22
|
-
allow_failures:
|
23
|
-
- rvm: ruby-head
|
24
|
-
gemfile: gemfiles/railsmaster.gemfile
|
data/Gemfile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in rubanok.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem "pry-byebug", platform: :mri
|
7
|
-
gem "simplecov"
|
8
|
-
|
9
|
-
local_gemfile = 'Gemfile.local'
|
10
|
-
|
11
|
-
if File.exist?(local_gemfile)
|
12
|
-
eval(File.read(local_gemfile)) # rubocop:disable Security/Eval
|
13
|
-
end
|
data/Gemfile.local
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
data/bin/setup
DELETED
data/gemfiles/rails42.gemfile
DELETED
data/gemfiles/rails52.gemfile
DELETED
data/lib/rubanok/plane.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rubanok/rule"
|
4
|
-
|
5
|
-
require "rubanok/dsl/mapping"
|
6
|
-
require "rubanok/dsl/matching"
|
7
|
-
|
8
|
-
require "rubanok/ext/symbolize_keys"
|
9
|
-
using Rubanok::SymbolizeKeys
|
10
|
-
|
11
|
-
module Rubanok
|
12
|
-
# Base class for transformers (_planes_)
|
13
|
-
#
|
14
|
-
# Define transformation rules via `map` and `match` methods
|
15
|
-
# and apply them by calling the plane:
|
16
|
-
#
|
17
|
-
# class MyPlane < Rubanok::Plane
|
18
|
-
# map :type do
|
19
|
-
# raw.where(type: type)
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# MyPlane.call(MyModel.all, {type: "public"})
|
24
|
-
#
|
25
|
-
# NOTE: the second argument (`params`) MUST be a Hash. Keys could be either Symbols
|
26
|
-
# or Strings (we automatically transform strings to symbols while matching rules).
|
27
|
-
#
|
28
|
-
# All transformation methods are called within the context of the instance of
|
29
|
-
# a plane class.
|
30
|
-
#
|
31
|
-
# You can access the input data via `raw` method.
|
32
|
-
class Plane
|
33
|
-
class << self
|
34
|
-
include DSL::Mapping
|
35
|
-
include DSL::Matching
|
36
|
-
|
37
|
-
def call(input, params)
|
38
|
-
new(input).call(params)
|
39
|
-
end
|
40
|
-
|
41
|
-
def add_rule(rule)
|
42
|
-
rules << rule
|
43
|
-
end
|
44
|
-
|
45
|
-
def rules
|
46
|
-
return @rules if instance_variable_defined?(:@rules)
|
47
|
-
|
48
|
-
@rules =
|
49
|
-
if superclass <= Plane
|
50
|
-
superclass.rules.dup
|
51
|
-
else
|
52
|
-
[]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def initialize(input)
|
58
|
-
@input = input
|
59
|
-
end
|
60
|
-
|
61
|
-
def call(params)
|
62
|
-
params = params.symbolize_keys
|
63
|
-
|
64
|
-
rules.each do |rule|
|
65
|
-
next unless rule.applicable?(params)
|
66
|
-
|
67
|
-
apply_rule! rule.to_method_name, rule.project(params)
|
68
|
-
end
|
69
|
-
|
70
|
-
input
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
attr_accessor :input
|
76
|
-
|
77
|
-
alias raw input
|
78
|
-
|
79
|
-
def apply_rule!(method_name, data)
|
80
|
-
self.input =
|
81
|
-
if data.empty?
|
82
|
-
send(method_name)
|
83
|
-
else
|
84
|
-
send(method_name, **data)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def rules
|
89
|
-
self.class.rules
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/rubanok.gemspec
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path("../lib", __FILE__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require "rubanok/version"
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = "rubanok"
|
9
|
-
spec.version = Rubanok::VERSION
|
10
|
-
spec.authors = ["Vladimir Dementyev"]
|
11
|
-
spec.email = ["dementiev.vm@gmail.com"]
|
12
|
-
|
13
|
-
spec.summary = "Parameters-based transformation DSL"
|
14
|
-
spec.description = "Parameters-based transformation DSL"
|
15
|
-
spec.homepage = "https://github.com/palkan/rubanok"
|
16
|
-
spec.license = "MIT"
|
17
|
-
spec.required_ruby_version = ">= 2.5.0"
|
18
|
-
|
19
|
-
# Specify which files should be added to the gem when it is released.
|
20
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
-
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
22
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
-
end
|
24
|
-
|
25
|
-
spec.require_paths = ["lib"]
|
26
|
-
|
27
|
-
spec.add_development_dependency "actionpack", ">= 4.2"
|
28
|
-
spec.add_development_dependency "actionview", ">= 4.2"
|
29
|
-
spec.add_development_dependency "bundler", ">= 1.16"
|
30
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
-
spec.add_development_dependency "rspec-rails"
|
33
|
-
spec.add_development_dependency "rubocop-rspec"
|
34
|
-
spec.add_development_dependency "standard"
|
35
|
-
end
|