rubanok 0.1.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
- Gemfile.lock
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
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
@@ -1,2 +0,0 @@
1
- gem "actionpack", "~> 5.2"
2
- gem "actionview", "~> 5.2"
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
- require "rubocop/rake_task"
6
-
7
- RSpec::Core::RakeTask.new(:spec)
8
- RuboCop::RakeTask.new
9
-
10
- task default: [:rubocop, :spec]
data/bin/console DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rubanok"
5
- require "pry"
6
-
7
- require "pry"
8
- Pry.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "actionpack", "~> 4.2"
4
- gem "actionview", "~> 4.2"
5
-
6
- gemspec path: ".."
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "actionpack", "~> 5.2"
4
- gem "actionview", "~> 5.2"
5
-
6
- gemspec path: ".."
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "rails", github: "rails/rails"
4
-
5
- gemspec path: ".."
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rubanok
4
- module SymbolizeKeys
5
- refine Hash do
6
- def symbolize_keys
7
- each_with_object({}) do |(key, value), acc|
8
- acc[key.to_sym] = value
9
- end
10
- end
11
- end
12
- end
13
- end
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