swifty_enum 0.1.1 → 0.1.2

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: 7c35dc6e44883857e7cf108027dc6d5c3985ff66
4
- data.tar.gz: db06cffa52a4d51e81add8838c3d35ffdb68defc
3
+ metadata.gz: 49b24144b99a4bfd84dfd0c01e5ab3a9dee0f33e
4
+ data.tar.gz: 40c17d11ed032c8c890588e1d118d73b3a1d954f
5
5
  SHA512:
6
- metadata.gz: 5226d77173da5b8374abd446d5b5757fe49e0d78245cb954514e23d853823e10b42c5dcee28e253bd0fb59ada8ea0ece6ab2d5c08acd23e4f3294bb7634999de
7
- data.tar.gz: fb88935bf3fcef5692a74868e84b4b392630f03a511a5edc61821a10a2088a7cdb61adbb02b0567e2c8e2ba37ba70db3dd10f47503ca2516b1d482e382bf1851
6
+ metadata.gz: 6414e553b226227623964baac4409efdde00682f93673746f37f8565d54d00c6840df6361f854deda7ffb51f511438c93332322a836445462cf1437667ad842c
7
+ data.tar.gz: 92fe919c450f04248908f856d3d96df3155111d82a2415e2c2b26e8e5ed70852d0a8a785c07d1f40b89cf5067258c11fa456db9c4ddb4e49342b8fb6b55a55a8
data/README.md CHANGED
@@ -37,13 +37,13 @@ class Flag
37
37
 
38
38
  # Now you can define enum case by 'def_case' statement.
39
39
  # Usage: def_case CASE_NAME [RAWVALUE]
40
- def_case 'On', '1'
41
- def_case 'Off', '0'
40
+ def_case :On, '1'
41
+ def_case :Off, '0'
42
42
 
43
- # You can also define method for each enum cases by 'def_method' statement.
43
+ # You can define method for each enum cases by 'def_method' statement.
44
44
  # Please put this statement below all of 'def_case' statements.
45
45
  # Usage: def_method METHOD_NAME { || ... }
46
- def_method 'status' do |enum_case|
46
+ def_method :status do |enum_case|
47
47
  case enum_case
48
48
  when On then
49
49
  # You can't use return statement, but value of last statement is returned from enum method.
@@ -52,6 +52,16 @@ class Flag
52
52
  'NG'
53
53
  end
54
54
  end
55
+
56
+ # You can also define method with variable arguments.
57
+ def_method :status_with do |enum_case, args|
58
+ if args.empty?
59
+ enum_case.status
60
+ else
61
+ about = args.join(', ')
62
+ "#{enum_case.status} with #{about}"
63
+ end
64
+ end
55
65
  end
56
66
 
57
67
 
@@ -88,6 +98,7 @@ end
88
98
  # Enum method is defined in each enum cases.
89
99
  Flag::On.status # => 'OK'
90
100
  Flag::Off.status # => 'NG'
101
+ Flag::On.status_with('foo') # => 'OK with foo'
91
102
 
92
103
  # When you want to get all of enum cases, use 'enum_cases'.
93
104
  Flag.enum_cases # => [Flag::On, Flag::Off]
@@ -57,8 +57,8 @@ module SwiftyEnum
57
57
  end
58
58
 
59
59
  @_enum_hash.values.each do |klass|
60
- klass.define_singleton_method name do
61
- yield klass
60
+ klass.define_singleton_method name do |*args|
61
+ yield klass, args
62
62
  end
63
63
  end
64
64
  end
@@ -1,3 +1,3 @@
1
1
  module SwiftyEnum
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swifty_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zeero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-18 00:00:00.000000000 Z
11
+ date: 2017-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler