rom-mapper 1.0.0.beta3 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3ed0e632f8f524f5ea414338cafefd5a836116c
4
- data.tar.gz: c951f650a48119ec07b7ba5f6d3bfaed29689d98
3
+ metadata.gz: 4d95a622f3bf3770ba84e599f757c4d88eca76ef
4
+ data.tar.gz: bb2c089f40d56fbcf4d6cb4ba3a0fdb66400bb83
5
5
  SHA512:
6
- metadata.gz: 457d4192340e27b180fa79949188f736a831d2266c545bc99e122eb7da65560571fd70bb4b9cfba23de88e374879aacb4fcf32a045c7e59d685391c1e66d4601
7
- data.tar.gz: 9d263dfdf5227861e2f34920cea183fca25576b712b91012cc0b615e77dc0003e7cb647ce66b5e6de97a52897e456cb48b879f3e1bb25a45aa1733d802008e46
6
+ metadata.gz: f54b0c3ffd3f9fee07b893b4a20a3b0598acc417ee9b2e69df6e2c590d16b47c98abd220084b9405d8f8ab0911981b77d696f5ad8d1f61b8d384cc1d5f5ab4b8
7
+ data.tar.gz: de6e65ecdc87305eedffca16deef93e73d02629cc07274280130431c65023b9ac791898c2c17034c1d7a06104e4eb68f9d045261d810cebc1b167d1d5c35d0dd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 1.0.0 to-be-released
2
+
3
+ ### Added
4
+
5
+ * New mapper type - `ROM::Transformer`, which exposes [transproc](https://github.com/solnic/transproc)'s DSL (solnic)
6
+
1
7
  # 0.5.1 2017-05-04
2
8
 
3
9
  ### Changed
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  class Mapper
3
- VERSION = '1.0.0.beta3'.freeze
3
+ VERSION = '1.0.0.rc1'.freeze
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ module ROM
9
9
  class MapperCompiler
10
10
  extend Initializer
11
11
 
12
- option :cache, reader: true, default: -> { Cache.new }
12
+ option :cache, default: -> { Cache.new }
13
13
 
14
14
  attr_reader :struct_compiler
15
15
 
@@ -17,11 +17,15 @@ module ROM
17
17
  param :registry, default: -> { Dry::Types }
18
18
  option :cache, default: -> { Cache.new }
19
19
 
20
+ # @api private
20
21
  def initialize(*args)
21
22
  super
22
23
  @cache = cache.namespaced(:structs)
23
24
  end
24
25
 
26
+ # Build a struct class based on relation header ast
27
+ #
28
+ # @api private
25
29
  def call(*args)
26
30
  cache.fetch_or_store(args) do
27
31
  name, header, ns = args
@@ -42,6 +46,7 @@ module ROM
42
46
 
43
47
  private
44
48
 
49
+ # @api private
45
50
  def visit_relation(node)
46
51
  _, header, meta = node
47
52
  name = meta[:combine_name] || meta[:alias]
@@ -57,36 +62,41 @@ module ROM
57
62
  end
58
63
 
59
64
  if meta[:combine_type] == :many
60
- [name, Types::Array.member(member)]
65
+ [name, Types::Array.of(member)]
61
66
  else
62
67
  [name, member.optional]
63
68
  end
64
69
  end
65
70
 
71
+ # @api private
66
72
  def visit_attribute(node)
67
73
  name, type, meta = node
68
74
 
69
75
  [meta[:alias] && !meta[:wrapped] ? meta[:alias] : name, visit(type).meta(meta)]
70
76
  end
71
77
 
78
+ # @api private
72
79
  def visit_constructor(node)
73
80
  definition, * = node
74
81
 
75
82
  visit(definition)
76
83
  end
77
84
 
85
+ # @api private
78
86
  def visit_constrained(node)
79
87
  definition, _ = node
80
88
 
81
89
  visit(definition)
82
90
  end
83
91
 
92
+ # @api private
84
93
  def build_class(name, parent, ns, &block)
85
94
  Dry::Core::ClassBuilder.
86
95
  new(name: class_name(name), parent: parent, namespace: ns).
87
96
  call(&block)
88
97
  end
89
98
 
99
+ # @api private
90
100
  def class_name(name)
91
101
  Dry::Core::Inflector.classify(Dry::Core::Inflector.singularize(name))
92
102
  end
@@ -0,0 +1,32 @@
1
+ require 'dry/core/class_attributes'
2
+ require 'transproc/transformer'
3
+
4
+ require 'rom/processor/transproc'
5
+
6
+ module ROM
7
+ # Transformer is a data mapper which uses Transproc's transformer DSL to define
8
+ # transformations.
9
+ #
10
+ # @api public
11
+ class Transformer < Transproc::Transformer[ROM::Processor::Transproc::Functions]
12
+ extend Dry::Core::ClassAttributes
13
+
14
+ defines :relation, :register_as
15
+
16
+ # This is needed to make transformers compatible with rom setup
17
+ #
18
+ # @api private
19
+ def self.base_relation
20
+ relation
21
+ end
22
+
23
+ # Build a mapper instance
24
+ #
25
+ # @return [Transformer]
26
+ #
27
+ # @api public
28
+ def self.build
29
+ new
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta3
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-14 00:00:00.000000000 Z
11
+ date: 2017-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-equalizer
@@ -113,6 +113,7 @@ files:
113
113
  - lib/rom/processor/transproc.rb
114
114
  - lib/rom/struct.rb
115
115
  - lib/rom/struct_compiler.rb
116
+ - lib/rom/transformer.rb
116
117
  homepage: http://rom-rb.org
117
118
  licenses:
118
119
  - MIT