mandate 0.1.2 → 0.2.0

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
- SHA1:
3
- metadata.gz: 4fa791b6c76c36108e70479ca079753fd356d565
4
- data.tar.gz: ac571723a8ea85395e999956c993ac2ab06e8541
2
+ SHA256:
3
+ metadata.gz: 8e2c86ccab594b7a9c1df7a455ab4949c36f23b9face3e07b91beab615398ded
4
+ data.tar.gz: 64fa8dbae3945ff3b5dc4fe7d5a1118dc4d64745351a3213a8297eedcebc2144
5
5
  SHA512:
6
- metadata.gz: 0e63e9220a06782b3f71444203599c33b1c960e95498a704763ad0750cd0d059dbbe6d58ee553a11eeb0f7d409796a57bdce14ae6aecadd94a2952371f7d4c3b
7
- data.tar.gz: 7533e79bef22e4732cdf9653e83184a2530585e1dda87d79981b429f323afc653a6ca81227b2d6d193c0b31380080e79a60e37b02f1296901b313ccdc91afc64
6
+ metadata.gz: e06458866a07824be2b0901778cd0f65b73a0b33458de8e92995028c7a2720e906f29dfc3b7c17ffb0b7d79d3bfb6c5669caceba730610eee729f53f2e5803fc
7
+ data.tar.gz: 007c3108ec701f6571ba7ea051d9c1933dc1dbe7645ccfd543a7173c43e9f29b428c12705726e776a1825df4bbfd58d3305983cb76b5b17639c0ffa19630c425
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # 0.2.0 / 2018-08-11
2
+ * [FEATURE] Add initialize_with
data/README.md CHANGED
@@ -25,11 +25,7 @@ Or install it yourself as:
25
25
  class Multiplies
26
26
  include Mandate
27
27
 
28
- attr_reader :number_1, :number_2
29
- def initialize(number_1, number_2)
30
- @number_1 = number_1
31
- @number_2 = number_2
32
- end
28
+ initialize_with :number_1, :number_2
33
29
 
34
30
  def call
35
31
  do_the_maths
@@ -48,6 +44,22 @@ Multiplies.(20, 3)
48
44
  # => 60
49
45
  ```
50
46
 
47
+ ### `initialize_with`
48
+
49
+ The `initialize_with` method creates an initializer and private attr_readers for the specified variables.
50
+
51
+ For example `initialize_with :foo, :bar` is the equivelent of:
52
+
53
+ ```
54
+ def initialize(foo, bar)
55
+ @foo = foo
56
+ @bar = bar
57
+ end
58
+
59
+ private
60
+ attr_reader :foo, :bar
61
+ ```
62
+
51
63
  ## Development
52
64
 
53
65
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,26 @@
1
+ module Mandate
2
+ module InitializerInjector
3
+ def self.extended(base)
4
+ class << base
5
+ def initialize_with(*attrs)
6
+ define_method :initialize do |*args|
7
+ unless args.length == attrs.length
8
+ raise ArgumentError.new("Wrong number of arguments (given #{args.length}, expected #{attrs.length})")
9
+ end
10
+
11
+ attrs.zip(args).each do |attr,arg|
12
+ instance_variable_set("@#{attr}", arg)
13
+ end
14
+ end
15
+
16
+ attrs.each do |attr|
17
+ define_method attr do instance_variable_get("@#{attr}") end
18
+ private attr
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+
@@ -1,3 +1,3 @@
1
1
  module Mandate
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/mandate.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require "mandate/version"
2
2
  require "mandate/memoize"
3
3
  require "mandate/call_injector"
4
+ require "mandate/initializer_injector"
4
5
 
5
6
  module Mandate
6
7
  def self.included(base)
7
8
  base.extend(Memoize)
8
9
  base.extend(CallInjector)
10
+ base.extend(InitializerInjector)
9
11
  end
10
12
  end
data/mandate.gemspec CHANGED
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.15"
25
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rake", "~> 12.3"
26
26
  spec.add_development_dependency "minitest", "~> 5.0"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2018-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -62,6 +62,7 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
64
  - ".travis.yml"
65
+ - CHANGELOG.md
65
66
  - Gemfile
66
67
  - LICENCE
67
68
  - README.md
@@ -70,6 +71,7 @@ files:
70
71
  - bin/setup
71
72
  - lib/mandate.rb
72
73
  - lib/mandate/call_injector.rb
74
+ - lib/mandate/initializer_injector.rb
73
75
  - lib/mandate/memoize.rb
74
76
  - lib/mandate/version.rb
75
77
  - mandate.gemspec
@@ -93,9 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
95
  version: '0'
94
96
  requirements: []
95
97
  rubyforge_project:
96
- rubygems_version: 2.6.13
98
+ rubygems_version: 2.7.7
97
99
  signing_key:
98
100
  specification_version: 4
99
101
  summary: A simple command-pattern helper gem for Ruby
100
102
  test_files: []
101
- has_rdoc: