contextualizer 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +4 -1
- data/bin/console +2 -2
- data/bin/rake +17 -0
- data/bin/rspec +17 -0
- data/contextualizer.gemspec +6 -1
- data/lib/contextualizer.rb +58 -3
- data/lib/contextualizer/version.rb +1 -1
- metadata +50 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec4c6dfc60a05baceb03c9a46c88175f09715cbf
|
4
|
+
data.tar.gz: 928070a99f1e191c845a31cf083cf9862f876f51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 947b5d582de538ecf810212daaf363f03d5382cdff6b9f8bac0d99c06d8408aa61c5cdb6eec30d8aed19cdc8049cfab1eb13e17450f04245b574181c66c2595c
|
7
|
+
data.tar.gz: 300ad39ac4e113e69ac14176b1e3f9a0b748ec934747c63b6b8187cbd0491dff4a9ad6d32ae5573bd70247b91b08f9b9552bcc20b14a42844775ad709550580b
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# Contextualizer
|
2
|
+
|
3
|
+
[![CircleCI](https://circleci.com/gh/pabloh/contextualizer/tree/master.svg?style=shield)](https://circleci.com/gh/pabloh/contextualizer/tree/master)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/pabloh/contextualizer/badge.svg?branch=master)](https://coveralls.io/github/pabloh/contextualizer?branch=master)
|
2
5
|
|
3
6
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/contextualizer`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
7
|
|
data/bin/console
CHANGED
data/bin/rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rake' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/contextualizer.gemspec
CHANGED
@@ -21,7 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.
|
24
|
+
spec.required_ruby_version = ">= 2.4.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", ">= 1.14.0"
|
25
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "coveralls"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
spec.add_development_dependency "pry-byebug"
|
27
32
|
end
|
data/lib/contextualizer.rb
CHANGED
@@ -1,5 +1,60 @@
|
|
1
|
-
|
1
|
+
module Contextualizer
|
2
|
+
def context(*attrs, **opt_attrs)
|
3
|
+
unless @_setter
|
4
|
+
@_setter = Setter.new
|
5
|
+
include Contextualizer.init_for(@_setter)
|
6
|
+
end
|
2
7
|
|
3
|
-
|
4
|
-
|
8
|
+
@_setter.add_attrs(*attrs, **opt_attrs)
|
9
|
+
attr_reader *attrs, *opt_attrs.keys
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.extended(klass)
|
13
|
+
klass.class_eval do
|
14
|
+
attr_reader :context
|
15
|
+
@_setter = Setter.new
|
16
|
+
include Contextualizer.init_for(@_setter, true)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.init_for(setter, first = false)
|
21
|
+
Module.new do |mod|
|
22
|
+
if first
|
23
|
+
mod.send(:define_method, :initialize) do |args = {}|
|
24
|
+
super()
|
25
|
+
setter.set(self, args)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
mod.send(:define_method, :initialize) do |args = {}|
|
29
|
+
super(args)
|
30
|
+
setter.set(self, args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Setter
|
37
|
+
def initialize
|
38
|
+
@attrs, @opt_attrs = [], {}
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_attrs(*attrs, **opt_attrs)
|
42
|
+
@attrs |= attrs
|
43
|
+
@opt_attrs.merge!(opt_attrs)
|
44
|
+
end
|
45
|
+
|
46
|
+
def set(obj, args)
|
47
|
+
context = obj.context&.dup || {}
|
48
|
+
|
49
|
+
@opt_attrs.each { |key, val| context[key] = args[key] || val }
|
50
|
+
@attrs.each { |key| context[key] = args[key] }
|
51
|
+
|
52
|
+
context.each do |attr, value|
|
53
|
+
fail ":#{attr} was not found in scope" if value.nil?
|
54
|
+
obj.instance_variable_set :"@#{attr}", value
|
55
|
+
end
|
56
|
+
|
57
|
+
obj.instance_variable_set(:@context, context.freeze)
|
58
|
+
end
|
59
|
+
end
|
5
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contextualizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Herrero
|
@@ -14,16 +14,16 @@ dependencies:
|
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.14.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.14.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,48 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
55
97
|
description: Allows to define context values for your objects
|
56
98
|
email:
|
57
99
|
- pablodherrero@gmail.com
|
@@ -67,6 +109,8 @@ files:
|
|
67
109
|
- README.md
|
68
110
|
- Rakefile
|
69
111
|
- bin/console
|
112
|
+
- bin/rake
|
113
|
+
- bin/rspec
|
70
114
|
- bin/setup
|
71
115
|
- contextualizer.gemspec
|
72
116
|
- lib/contextualizer.rb
|
@@ -83,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
127
|
requirements:
|
84
128
|
- - ">="
|
85
129
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
130
|
+
version: 2.4.0
|
87
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
132
|
requirements:
|
89
133
|
- - ">="
|