easily_typable 1.0.1 → 1.0.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.
Files changed (4) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +40 -43
  3. data/lib/easily_typable.rb +1 -1
  4. metadata +31 -80
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NmY1Y2QzNjQ1N2VlNDk1NWY1YTg5MTg5MGY3YThhNDE3NGQ0ZjkxYw==
5
- data.tar.gz: !binary |-
6
- M2JkZGI4MDcxMGI5ZGJjOTM3NWI1MTg4ZThjZGNkZDk4ODY2ODAzMw==
2
+ SHA256:
3
+ metadata.gz: ed4faa7f4ff1f8e379e5c6f23afec58eb0e27ad9b9f51392f8049084a65bb152
4
+ data.tar.gz: e843e5c966e7b2485adc48e2e53e7f28b5a0fe66b244187fd778932b74d93e5e
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MjExM2RmYTM1MWE5MjgxMTU5NmU0Yjg5MGQ2OGUzYjMwNDEzZGEwNTkxMTVk
10
- MDg0NWI0MGMxNDY2NjAzZjY4Zjk1NDAwYmIyMjg3YzYwY2JjYmE4MjMzNmM4
11
- ZmZmYzZmZjdjZjYxNTZiYzVlMDlmZmRhODdjZTRjNmZmNmEzMGM=
12
- data.tar.gz: !binary |-
13
- NWE4NGRlOTFiMGMyYzgyZmMxNGE1MGRmYjNkMjQ0MDZiZDZlZDQzYWE3ZmU4
14
- ZDM2YzM2MjI5MDBjN2NhMTVlOWNiNGY4YjRkYmU2MjEzZjMwMGQyNzQ4Nzk4
15
- M2NkOGZhMmUyNmVmMmMxNDdiODc0OGFjY2E3MjEzMTk1MDUzNTQ=
6
+ metadata.gz: ef6df638fc0994ffc19817757b23e6a877e1c6627b469b107a3996738525f3430bf408d0d14a57965f383df69588705bfaada1dfcfcbb6510cbded4fdf22854f
7
+ data.tar.gz: 8cf929730badfba15058d93b3984d217c0a16adacf40e9e24f6ac9b1fa17e0d574c7dc67bc3eff088349b82f57a676c74cfc027373e51814721e5bec0010b2f8
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # Easily Typable v1.0.1
1
+ # Easily Typable v1.0.2
2
2
  [![Gem Version](https://badge.fury.io/rb/easily_typable.svg)](http://badge.fury.io/rb/easily_typable)
3
3
  [![Build Status](https://api.travis-ci.org/AndyObtiva/easily_typable.svg?branch=master)](https://travis-ci.org/AndyObtiva/easily_typable)
4
- [![Coverage Status](https://coveralls.io/repos/AndyObtiva/easily_typable/badge.svg?branch=master)](https://coveralls.io/r/AndyObtiva/easily_typable?branch=master)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/61a688078896badc104f/test_coverage)](https://codeclimate.com/github/AndyObtiva/easily_typable/test_coverage)
5
5
  [![Code Climate](https://codeclimate.com/github/AndyObtiva/easily_typable.svg)](https://codeclimate.com/github/AndyObtiva/easily_typable)
6
6
 
7
7
  ## Introduction:
@@ -19,11 +19,14 @@ parts of the view:
19
19
  <% if user.is_a?(Admin) %>
20
20
  <%= link_to 'Admin', admin_dashboard_path %>
21
21
  <% end %>
22
+ <% if user.is_a?(Customer) %>
23
+ <%= link_to 'Customer Profile', customer_profile_path %>
24
+ <% end %>
22
25
  ```
23
26
 
24
- To avoid the ```model.is_a?(CertainType)``` syntax, a more readable approach
25
- that developers resort to is to add an English-like method that hides the
26
- details of type checking ```model.certain_type?```.
27
+ To avoid the `model.is_a?(Admin)` syntax, a more readable approach
28
+ that developers resort to is to add an English-like DSL method that hides the
29
+ details of Object-Oriented type checking: `model.admin?`.
27
30
 
28
31
  The Rails example above would then become:
29
32
 
@@ -31,61 +34,56 @@ The Rails example above would then become:
31
34
  <% if user.admin? %>
32
35
  <%= link_to 'Admin', admin_dashboard_path %>
33
36
  <% end %>
37
+ <% if user.customer? %>
38
+ <%= link_to 'Customer Profile', customer_profile_path %>
39
+ <% end %>
34
40
  ```
35
41
 
36
- Implementing such methods manually gets repetitive after a while, so an easier
42
+ Implementing such methods manually gets repetitive and error-prone, so an easier
37
43
  way to get these methods automatically is to mixin the ```EasilyTypable```
38
44
  module.
39
45
 
40
46
  ## Example:
41
47
 
42
48
  ```ruby
43
- require 'easily_typable'
49
+ require 'easily_typable' # in IRB at cloned project directory, call this instead: require './lib/easily_typable'
44
50
 
45
- class TypeA
51
+ class Vehicle
46
52
  include EasilyTypable
47
53
  end
48
54
 
49
- class TypeB < TypeA
55
+ class Car < Vehicle
50
56
  end
51
57
 
52
- class TypeC < TypeB
58
+ class Truck < Vehicle
53
59
  end
54
60
 
55
- ## RSpec of Easily Typable
56
- require 'spec_helper'
57
-
58
- describe EasilyTypable do
59
- it "adds type_a? method to TypeA object" do
60
- expect(TypeA.new.type_a?).to be_truthy
61
- end
62
- it "adds type_b? method to TypeA object" do
63
- expect(TypeA.new.type_b?).to be_falsey
64
- end
65
- it "adds type_c? method to TypeA object" do
66
- expect(TypeA.new.type_c?).to be_falsey
67
- end
68
- it "adds type_a? method to TypeB object" do
69
- expect(TypeB.new.type_a?).to be_truthy
70
- end
71
- it "adds type_b? method to TypeB object" do
72
- expect(TypeB.new.type_b?).to be_truthy
73
- end
74
- it "adds type_c? method to TypeB object" do
75
- expect(TypeB.new.type_c?).to be_falsey
76
- end
77
- it "adds type_a? method to TypeC object" do
78
- expect(TypeC.new.type_a?).to be_truthy
79
- end
80
- it "adds type_b? method to TypeC object" do
81
- expect(TypeC.new.type_b?).to be_truthy
82
- end
83
- it "adds type_c? method to TypeC object" do
84
- expect(TypeC.new.type_c?).to be_truthy
85
- end
61
+ class Van < Vehicle
86
62
  end
63
+
64
+
65
+ puts Car.new.vehicle? # prints true
66
+ puts Car.new.car? # prints true
67
+ puts Car.new.truck? # prints false
68
+ puts Car.new.van? # prints false
69
+
70
+ puts Truck.new.vehicle? # prints true
71
+ puts Truck.new.car? # prints false
72
+ puts Truck.new.truck? # prints true
73
+ puts Truck.new.van? # prints false
74
+
75
+ puts Van.new.vehicle? # prints true
76
+ puts Van.new.car? # prints false
77
+ puts Van.new.truck? # prints false
78
+ puts Van.new.van? # prints true
87
79
  ```
88
80
 
81
+ ## Release Notes
82
+
83
+ * v1.0.2: Support namespaced subclasses
84
+ * v1.0.1: Rails model lazy loading now loads EasilyTypable methods automagically
85
+ * v1.0.0: Initial Easily Typable implementation for Ruby
86
+
89
87
  ## Contributing to Easily Typable
90
88
 
91
89
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -98,6 +96,5 @@ end
98
96
 
99
97
  ## Copyright
100
98
 
101
- * Copyright (c) 2012 - 2017 Andy Maleh
102
- * Copyright (c) 2009 - 2011 Andy Maleh - Obtiva Corp.
99
+ * Copyright (c) 2009-2020 Andy Maleh
103
100
  * See LICENSE.txt for further details.
@@ -55,7 +55,7 @@ module EasilyTypable
55
55
  protected
56
56
  #added this method to break reliance on ActiveSupport and Facets
57
57
  def self.__methodize__(text)
58
- text.gsub(/([A-Z]+)([A-Z])/,'\1_\2').
58
+ text.split(/::/).last.gsub(/([A-Z]+)([A-Z])/,'\1_\2').
59
59
  gsub(/([a-z])([A-Z])/,'\1_\2').
60
60
  downcase
61
61
  end
metadata CHANGED
@@ -1,164 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easily_typable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyObtiva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2020-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeweler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.1
19
+ version: 2.3.9
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: 2.0.1
26
+ version: 2.3.9
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 5.0.0
33
+ version: 6.2.1
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: 5.0.0
40
+ version: 6.2.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.5.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.5.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.8.5
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '='
67
- - !ruby/object:Gem::Version
68
- version: 0.8.5
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- version: 0.10.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.10.0
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: codeclimate-test-reporter
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
- - - ~>
59
+ - - "~>"
88
60
  - !ruby/object:Gem::Version
89
- version: 1.0.5
61
+ version: 1.0.7
90
62
  type: :development
91
63
  prerelease: false
92
64
  version_requirements: !ruby/object:Gem::Requirement
93
65
  requirements:
94
- - - ~>
66
+ - - "~>"
95
67
  - !ruby/object:Gem::Version
96
- version: 1.0.5
68
+ version: 1.0.7
97
69
  - !ruby/object:Gem::Dependency
98
70
  name: rake
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
- - - ~>
73
+ - - "~>"
102
74
  - !ruby/object:Gem::Version
103
- version: 10.4.2
75
+ version: 13.0.1
104
76
  type: :development
105
77
  prerelease: false
106
78
  version_requirements: !ruby/object:Gem::Requirement
107
79
  requirements:
108
- - - ~>
80
+ - - "~>"
109
81
  - !ruby/object:Gem::Version
110
- version: 10.4.2
82
+ version: 13.0.1
111
83
  - !ruby/object:Gem::Dependency
112
84
  name: rack
113
85
  requirement: !ruby/object:Gem::Requirement
114
86
  requirements:
115
- - - ~>
87
+ - - "~>"
116
88
  - !ruby/object:Gem::Version
117
89
  version: 1.6.5
118
90
  type: :development
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
93
  requirements:
122
- - - ~>
94
+ - - "~>"
123
95
  - !ruby/object:Gem::Version
124
96
  version: 1.6.5
125
- - !ruby/object:Gem::Dependency
126
- name: nokogiri
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ~>
130
- - !ruby/object:Gem::Version
131
- version: 1.6.8.1
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ~>
137
- - !ruby/object:Gem::Version
138
- version: 1.6.8.1
139
97
  - !ruby/object:Gem::Dependency
140
98
  name: term-ansicolor
141
99
  requirement: !ruby/object:Gem::Requirement
142
100
  requirements:
143
- - - ~>
101
+ - - "~>"
144
102
  - !ruby/object:Gem::Version
145
103
  version: 1.3.2
146
104
  type: :development
147
105
  prerelease: false
148
106
  version_requirements: !ruby/object:Gem::Requirement
149
107
  requirements:
150
- - - ~>
108
+ - - "~>"
151
109
  - !ruby/object:Gem::Version
152
110
  version: 1.3.2
153
- description: Although polymorphism is a recommended standard in Object-Oriented programming
154
- for invoking varied behavior in an inheritance hierarchy, sometimes it is still
155
- useful to verify if a particular model belongs to a certain type when the behavior
156
- concerned does not belong to the model and is too small to require a Design Pattern
157
- like Strategy. To avoid the model.is_a?(CertainType) syntax, a more readable approach
158
- that developers resort to is to add an English-like method that hides the details
159
- of type checking model.certain_type?. Implementing such methods manually gets repetitive
160
- after a while, so an easier way to get these methods automatically is to mixin the
161
- EasilyTypable module.
111
+ description: Ruby mixin that facilitates English-like type checking in an inheritance
112
+ hierarchy via "type_name?" methods
162
113
  email: andy.am@gmail.com
163
114
  executables: []
164
115
  extensions: []
@@ -179,18 +130,18 @@ require_paths:
179
130
  - lib
180
131
  required_ruby_version: !ruby/object:Gem::Requirement
181
132
  requirements:
182
- - - ! '>='
133
+ - - ">="
183
134
  - !ruby/object:Gem::Version
184
135
  version: '0'
185
136
  required_rubygems_version: !ruby/object:Gem::Requirement
186
137
  requirements:
187
- - - ! '>='
138
+ - - ">="
188
139
  - !ruby/object:Gem::Version
189
140
  version: '0'
190
141
  requirements: []
191
- rubyforge_project:
192
- rubygems_version: 2.4.8
142
+ rubygems_version: 3.1.2
193
143
  signing_key:
194
144
  specification_version: 4
195
- summary: Easier type checking via auto-generated certain_type? methods
145
+ summary: Ruby mixin that facilitates English-like type checking in an inheritance
146
+ hierarchy via "type_name?" methods
196
147
  test_files: []