attire 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/attire.rb +25 -21
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e182d55a0029623e5a05e47f92701bbe3fd55e2
4
- data.tar.gz: 2d209d7daf659e2bef9e5f7da389641ab0d7c99f
3
+ metadata.gz: 846310cee11e1fedbc86238e416787070404a122
4
+ data.tar.gz: 2b62ef8468309877f57edd7cfef43ec6a22f7652
5
5
  SHA512:
6
- metadata.gz: 5fa120c1f70fedb9a5a3f93173444bd054269ba6eaa9d9881b5e89b24b39aad1d33abdc25c6c1940138e8d4562a003c87fd4531c5313a9cbbe50bfbded357cf0
7
- data.tar.gz: 8b0e10d88064358730c4ff416e5f9f90b56b6fd01a951389651ccb6e205e47528e78b6bf227226d34fec0e0dfe286138384901c4df3e799c0e8ce03a2134a5f2
6
+ metadata.gz: bbfce629ad166304f68f845dbcaf3a8a19c889023c305c1cba87aeb653c92577bba7d25e755d9286b2131045d7c8d11a89f38a00616ce1fd0622d39d13f9321b
7
+ data.tar.gz: c7a3f0d225cba83bac4d5492b6ad46fd5e7dbb7b35f8191c57d18d174bbf18b22e7e8fe060dbd94b61be2a279563c2e9f7b87c73c1223e59256e852de340b56e
@@ -1,32 +1,36 @@
1
1
  module Attire
2
- def attire(param_str, method: :initialize, verb: nil, &after)
3
- names = eval("->(#{param_str}){}").parameters.map(&:last)
4
- def_init(param_str, method, names)
5
- add_getters(names)
6
- define_method(:__after) { instance_exec(&after) if after }
7
- def_verb(verb) if verb
8
- end
2
+ class << self
3
+ def attire(base, param_str, method: :initialize, verb: nil, &after)
4
+ names = eval("->(#{param_str}){}").parameters.map(&:last)
5
+ def_init(base, param_str, method, names)
6
+ add_getters(base, names)
7
+ base.send(:define_method, :__after) { instance_exec(&after) if after }
8
+ def_verb(base, verb) if verb
9
+ end
9
10
 
10
- private
11
+ private
11
12
 
12
- def def_init(param_str, method, names)
13
- class_eval "def #{method}(#{param_str})\n#{ivars(names)}\n__after\nend"
14
- end
13
+ def def_init(base, param_str, method, names)
14
+ base.class_eval "def #{method}(#{param_str})\n#{ivars(names)}\n__after\nend"
15
+ end
15
16
 
16
- def ivars(names)
17
- names.map { |name| "@#{name} = #{name}\n" }.join
18
- end
17
+ def ivars(names)
18
+ names.map { |name| "@#{name} = #{name}\n" }.join
19
+ end
19
20
 
20
- def add_getters(names)
21
- attr_reader(*names)
22
- private(*names)
23
- end
21
+ def add_getters(base, names)
22
+ base.send(:attr_reader, *names)
23
+ base.send(:private, *names)
24
+ end
24
25
 
25
- def def_verb(verb)
26
- define_singleton_method(verb) { |*a, **k, &b| new(*a, **k, &b).send(verb) }
26
+ def def_verb(base, verb)
27
+ base.define_singleton_method(verb) { |*a, &b| new(*a, &b).send(verb) }
28
+ end
27
29
  end
28
30
  end
29
31
 
30
32
  class Module
31
- include Attire
33
+ def attire(*a, &b)
34
+ Attire.attire(self, *a, &b)
35
+ end
32
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attire
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec