massager 0.1.0 → 0.1.1

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: 2672bbe80f0946944247fc60fc911d75a5a2cb80
4
- data.tar.gz: bd662e2698a6454d244e36a122be9f3413927fe7
3
+ metadata.gz: 0de927f4b6c1c57de9734a7f173c9c2429f29fee
4
+ data.tar.gz: b76f29ffbd8e782c8a00a28f38c5001be83f6ef1
5
5
  SHA512:
6
- metadata.gz: ef71c6777a22387858f185f95d1d6b40114e134fbe0c447ea4e176dcfcada9074fe00502ef2272b5287fcff5676aba11cb2995e720af3545f0bfb70a2590b56c
7
- data.tar.gz: 1579f8f4d3d464be00d3d900af8130e2e5ab6eb1f95f753a5ee5fdec5076cf2e5b9d289dd17cf284bc0e46f8a5cfe151c317c74ec82af44396574223ac8f6a80
6
+ metadata.gz: 3a444f625b9641cc69b4c944c9170164ea28e1e8aec0967237db696bd9cbfa278cf1ec7fcf0fe345346cf6d3db3fec5a49d36ba28fcb2ac28c9c7138b97b1ed2
7
+ data.tar.gz: a56754ed98e5b0861beccd7ef7e45c38727c5697cdb7466a5fcf1a6f0d46b25139e499d391d956bf717607aa88b5724129f557cd73ecdaf178e525f5974acd69
@@ -1,3 +1,3 @@
1
1
  module Massager
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/massager.rb CHANGED
@@ -3,25 +3,14 @@ require "dry-types"
3
3
  require "dry-monads"
4
4
  require "dry-container"
5
5
 
6
+
6
7
  module Massager
7
8
  module ClassMethods
8
9
  def column(name, target_key, type: nil, &block)
9
10
  set_container
10
-
11
- container.register(target_key) do
12
- {name: name, target_key: target_key, type: Dry::Monads::Maybe(type), block: Dry::Monads::Maybe(block)}
13
- end
14
-
15
- define_method name, Proc.new {
16
- instance_variable_get(:"@#{name}")
17
- }
18
-
19
- define_method "#{name}=", Proc.new {|val|
20
- container = self.class.container.resolve(target_key)
21
- container[:block].fmap {|v| val = v.call(val)}
22
- container[:type].fmap {|v| val = v[val]}
23
- instance_variable_set(:"@#{name}", val)
24
- }
11
+ register_column_info(target_key, name, type, block)
12
+ define_setter(target_key)
13
+ define_getter(target_key)
25
14
  end
26
15
 
27
16
  def build(attrs)
@@ -40,6 +29,28 @@ module Massager
40
29
  @container ||= Dry::Container.new
41
30
  end
42
31
  end
32
+
33
+ def define_setter(target_key)
34
+ container = self.container.resolve(target_key)
35
+ define_method "#{container[:name]}=", Proc.new {|val|
36
+ container[:block].fmap {|v| val = v.call(val)}
37
+ container[:type].fmap {|v| val = v[val]}
38
+ instance_variable_set(:"@#{container[:name]}", val)
39
+ }
40
+ end
41
+
42
+ def define_getter(target_key)
43
+ container = self.container.resolve(target_key)
44
+ define_method container[:name], Proc.new {
45
+ instance_variable_get(:"@#{container[:name]}")
46
+ }
47
+ end
48
+
49
+ def register_column_info(target_key, name, type, block)
50
+ container.register(target_key) do
51
+ {name: name, target_key: target_key, type: Dry::Monads::Maybe(type), block: Dry::Monads::Maybe(block)}
52
+ end
53
+ end
43
54
  end
44
55
 
45
56
  def self.included(base)
@@ -47,6 +58,3 @@ module Massager
47
58
  end
48
59
  end
49
60
 
50
- module Types
51
- include Dry::Types.module
52
- end
data/massager.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Janis Miezitis"]
10
10
  spec.email = ["janjiss@gmail.com"]
11
11
 
12
- spec.summary = %q{Write a short summary, because Rubygems requires one.}
13
- spec.description = %q{Write a longer description or delete this line.}
12
+ spec.summary = %q{Massager is a gem that helps to transform the data}
13
+ spec.description = %q{Massager is built for CSV row parsing and transforming, but there is no reason not to use it on plain hashes}
14
14
  spec.homepage = "http://github.com/janjiss/massager"
15
15
  spec.license = "MIT"
16
16
 
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 1.12"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "pry", "~> 0.10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: massager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janis Miezitis
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.10.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.10.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,8 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
- description: Write a longer description or delete this line.
83
+ description: Massager is built for CSV row parsing and transforming, but there is
84
+ no reason not to use it on plain hashes
84
85
  email:
85
86
  - janjiss@gmail.com
86
87
  executables: []
@@ -124,5 +125,5 @@ rubyforge_project:
124
125
  rubygems_version: 2.5.1
125
126
  signing_key:
126
127
  specification_version: 4
127
- summary: Write a short summary, because Rubygems requires one.
128
+ summary: Massager is a gem that helps to transform the data
128
129
  test_files: []