selfies 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 345c53269ed74a93dc3168e643a651c3992e4746
4
- data.tar.gz: 3ebc68af81e38e1f6120f63177c36915203cf62e
3
+ metadata.gz: 542d2ed712992bff31b812fe7f1fce625e603cca
4
+ data.tar.gz: 731f48a656f0d3817792c5751581555f5cf6d4b4
5
5
  SHA512:
6
- metadata.gz: 81dafb7921d9ef47ea6d401d79be5245a704c5c124254757127d05b14ead0ba752f5cd3f6bd3f24b702c8e21afb72aab3d7dc55bb3bc38546142e5e87e781a4c
7
- data.tar.gz: 38640018338ce5a7bec49fba1cc28f1db500ef186a1f82cbad36416fe68ccd10da668952e89337901af4f15cc35f47efae0d4116f72ce5285b2d72d73bc8b342
6
+ metadata.gz: de4fc0461686a7f5ea01b802288193c29a1fd5f5ba5eee929661ff062ae6db2456b02a726d5ea1cab9cd6726baa68c7465deea6c530f81c706d86aeae074919e
7
+ data.tar.gz: 5124a761f0f2760eaca91e593cf764e0a2ec36800aa1218adb0e705b398c1ccb98d90588f1fc16cbd487c7b087e58ae222b63b76270c5adb1711a10df9e62bac
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Gem Version](https://badge.fury.io/rb/selfies.svg)](https://badge.fury.io/rb/selfies) [![Dependency Status](https://gemnasium.com/badges/github.com/mariodarco/selfies.svg)](https://gemnasium.com/github.com/mariodarco/selfies) [![CircleCI](https://circleci.com/gh/mariodarco/selfies/tree/master.svg?style=shield)](https://circleci.com/gh/mariodarco/selfies/tree/master)
1
+ [![Gem Version](https://badge.fury.io/rb/selfies.svg)](https://badge.fury.io/rb/selfies) [![Dependency Status](https://gemnasium.com/badges/github.com/mariodarco/selfies.svg)](https://gemnasium.com/github.com/mariodarco/selfies) [![CircleCI](https://circleci.com/gh/mariodarco/selfies/tree/master.svg?style=shield)](https://circleci.com/gh/mariodarco/selfies/tree/master) [![Maintainability](https://api.codeclimate.com/v1/badges/fe208e3abde2e2937ac7/maintainability)](https://codeclimate.com/github/mariodarco/selfies/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/fe208e3abde2e2937ac7/test_coverage)](https://codeclimate.com/github/mariodarco/selfies/test_coverage)
2
2
 
3
3
  # Selfies
4
4
  **A collection of macros for quicker development**
@@ -250,7 +250,7 @@ end
250
250
  - Find a suitable syntax that would allow to 'selfie' an instance method that has arguments;
251
251
 
252
252
  ***command line:***
253
- - Write a command that can initialize a whole class, from creating the file to stub the initial setup (idea by Luke Hill)
253
+ - Write a command that can initialize a whole class, from creating the file to stub the initial setup;
254
254
 
255
255
  ***more?:***
256
256
  - If you also often write repetitive bolierplate, and would like some code to get smaller, drop me a line and we might be able to add more macros.
@@ -9,50 +9,52 @@ module Selfies
9
9
  SelfInit.access_variables(class_name, accessor, variable_names)
10
10
 
11
11
  define_method(:initialize) do |*args|
12
- argument_count(variables, variable_names.count, args.count)
12
+ SelfInit.argument_guard(variables, variable_names.count, args.count)
13
13
 
14
14
  variables.each_with_index do |variable, index|
15
- variable_name, default = decouple(variable)
15
+ variable_name, default = SelfInit.decouple(variable)
16
16
  value = variable_name == :args ? args[index..-1] : args[index]
17
17
  instance_variable_set("@#{variable_name}", value || default)
18
18
  end
19
19
  end
20
-
21
- define_method(:argument_count) do |all_variables, expected, given|
22
- unless correct_argument_count?(all_variables, expected, given)
23
- raise ArgumentError,
24
- "wrong number of arguments (given #{given}, expected #{expected})"
25
- end
26
- end
27
-
28
- define_method(:correct_argument_count?) do |all_variables, expected, given|
29
- final_variable = all_variables.last
30
- correct_argument_count = given == expected
31
- if final_variable.is_a? Hash
32
- correct_argument_count ||= given == expected - 1
33
- elsif final_variable == :args
34
- at_least = all_variables[0..all_variables.index(:args)].count
35
- correct_argument_count ||= given >= at_least
36
- end
37
-
38
- correct_argument_count
39
- end
40
-
41
- define_method(:decouple) do |variable|
42
- return [variable, nil] unless variable.is_a? Hash
43
-
44
- variable.keys + variable.values
45
- end
46
20
  end
47
21
  end
48
22
 
49
23
  def self.access_variables(class_name, accessor, variable_names)
50
24
  class_name.send(
51
25
  (accessor ? :attr_accessor : :attr_reader),
52
- *(variable_names)
26
+ *variable_names
53
27
  )
54
28
  end
55
29
 
30
+ def self.argument_guard(all_variables, expected, given)
31
+ unless correct_argument_count?(all_variables, expected, given)
32
+ raise(
33
+ ArgumentError,
34
+ "wrong number of arguments (given #{given}, expected #{expected})"
35
+ )
36
+ end
37
+ end
38
+
39
+ def self.correct_argument_count?(all_variables, expected, given)
40
+ final_variable = all_variables.last
41
+ correct_argument_count = given == expected
42
+ if final_variable.is_a? Hash
43
+ correct_argument_count ||= given == expected - 1
44
+ elsif final_variable == :args
45
+ at_least = all_variables[0..all_variables.index(:args)].count
46
+ correct_argument_count ||= given >= at_least
47
+ end
48
+
49
+ correct_argument_count
50
+ end
51
+
52
+ def self.decouple(variable)
53
+ return [variable, nil] unless variable.is_a? Hash
54
+
55
+ variable.keys + variable.values
56
+ end
57
+
56
58
  def self.variable_names(variables)
57
59
  variables.collect do |variable|
58
60
  variable.is_a?(Hash) ? variable.keys.first : variable
@@ -1,3 +1,3 @@
1
1
  module Selfies
2
- VERSION = '1.2.2'.freeze
2
+ VERSION = '1.2.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selfies
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario D’Arco
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler