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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85a5d7ddf95f6f8b4f92cb9321b83fe392de8e64
4
- data.tar.gz: fc3d0d47f870561132f208f0ed3948e9074a05d4
3
+ metadata.gz: ec4c6dfc60a05baceb03c9a46c88175f09715cbf
4
+ data.tar.gz: 928070a99f1e191c845a31cf083cf9862f876f51
5
5
  SHA512:
6
- metadata.gz: b3bbfb04c60c0b73e3bd56cc851d13a2c176a7575cd55c8584e7de05c9bbdb19d79d10555a60eb44f195dee1c6e3890b6e58546c2ceff2268fdf2bb5170af4c7
7
- data.tar.gz: 5bee49d175a2fcaf48f9a0c9629aa31e33da911f4db6549fe4855b0e6352f1d1aaf5804e5de863983c809f2b2b60a3742f122200a637620cffc95c9633e27914
6
+ metadata.gz: 947b5d582de538ecf810212daaf363f03d5382cdff6b9f8bac0d99c06d8408aa61c5cdb6eec30d8aed19cdc8049cfab1eb13e17450f04245b574181c66c2595c
7
+ data.tar.gz: 300ad39ac4e113e69ac14176b1e3f9a0b748ec934747c63b6b8187cbd0491dff4a9ad6d32ae5573bd70247b91b08f9b9552bcc20b14a42844775ad709550580b
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ ruby '2.4.0'
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in contextualizer.gemspec
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # Contextualized
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
 
@@ -10,5 +10,5 @@ require "contextualizer"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
14
- IRB.start(__FILE__)
13
+ require "pry"
14
+ Pry.start(Contextualizer)
@@ -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")
@@ -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")
@@ -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.add_development_dependency "bundler", "~> 1.15"
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
@@ -1,5 +1,60 @@
1
- require "contextualizer/version"
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
- module Contextualized
4
- # Your code goes here...
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
@@ -1,3 +1,3 @@
1
1
  module Contextualizer
2
- VERSION = "0.0.0"
2
+ VERSION = "0.0.1"
3
3
  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.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: '1.15'
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: '1.15'
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: '0'
130
+ version: 2.4.0
87
131
  required_rubygems_version: !ruby/object:Gem::Requirement
88
132
  requirements:
89
133
  - - ">="