mabbre 0.0.1 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5db2c5a298a84213898b57446f49f5f19f010b0
4
- data.tar.gz: 1398a1fc8fef6a48ebfc1639674c3bf88369ec13
3
+ metadata.gz: c016656016fd3c08ce23dfa62e5c13068d7ad20d
4
+ data.tar.gz: 543dfd9db25ba624fa8f7a5295313b624ec9c347
5
5
  SHA512:
6
- metadata.gz: 98edd86d51eed250ee24289b614e4b986aaae0f6b2c22d40eba048cca89849050e6b6802d7169dcbe82e259fe634cfdd57c75ee193604d8898d90f3c5a7afca1
7
- data.tar.gz: 2e1e614d03708c085c1dc5b4de9765ce677c8217344ae2ad636f2ae1a23a49d030bcf38bba157e5b4770a103da2e9b3581f132b1fcacd82b3c0bc05c0656b6ec
6
+ metadata.gz: 08ff8ad423c2967b4eef88c51450533917cb3adcf570d66a87406256d2e9a928af095e46ffa311f9996f87d82f57e2fd4818d329b5eef7e6dec55c5e3f5de7ae
7
+ data.tar.gz: 98a2a1222e1e7dbd2544f29f8b5adabea5d4860322277bc58b5b9264ea2ebaee7a131ced8fb4c173246fd856b87678daedf632b68f4e788394d4cc6cea0d4732
data/.rubocop.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  Metrics/LineLength:
2
2
  Max: 120
3
+ Style/AndOr:
4
+ EnforcedStyle: conditionals
3
5
  Style/HashSyntax:
4
6
  EnforcedStyle: hash_rockets
5
7
  Style/SpaceInsideBlockBraces:
data/README.md CHANGED
@@ -36,6 +36,8 @@ Or install it yourself as:
36
36
  Step 1: Define methods within an `allow_abbreviated` block in a Class or a Module:
37
37
 
38
38
  ```ruby
39
+ require "mabbre"
40
+
39
41
  module M
40
42
  extend MAbbre::Mixin
41
43
  allow_abbreviated do
@@ -0,0 +1,49 @@
1
+ module MAbbre # rubocop:disable Style/Documentation
2
+ ##
3
+ # This is a temporary module that is run when loading MAbbre in order to add patches on some Ruby
4
+ # versions/implementations. After the environment is patched it will be automatically removed.
5
+ module Compatibility
6
+ ##
7
+ # Relative path to the directory where patch files for the Object class live.
8
+ PATH_TO_OBJECT_PATCHES = "mabbre/patch/object_mixin".freeze
9
+
10
+ ##
11
+ # A hash of patch names for the Object class. Each patch name has a +true+ or +false+ value assigned that represents
12
+ # if they need to be applied or not.
13
+ OBJECT_PATCHES = {
14
+ :respond_to_missing => !Object.private_instance_methods.map(&:to_sym).include?(:respond_to_missing?)
15
+ }.freeze
16
+
17
+ class << self
18
+ private
19
+
20
+ ##
21
+ # call-seq:
22
+ # init_self() => nil
23
+ #
24
+ # This method is automatically called by this module in order to apply all patches.
25
+ #
26
+ # Returns a +nil+ value.
27
+ def init_self
28
+ check_object
29
+ nil
30
+ end
31
+
32
+ ##
33
+ # call-seq:
34
+ # check_object() => Object or nil
35
+ #
36
+ # Checks all available patches for the Object class and applies the ones that are needed.
37
+ #
38
+ # Returns Object if patches were applied or +nil+ otherwise.
39
+ def check_object
40
+ OBJECT_PATCHES.each {|patch, needed| require "#{PATH_TO_OBJECT_PATCHES}/#{patch}" if needed }
41
+ Object.instance_eval { include Patch::ObjectMixin } if OBJECT_PATCHES.values.any?
42
+ end
43
+ end
44
+
45
+ init_self
46
+ end
47
+
48
+ remove_const :Compatibility
49
+ end
@@ -19,5 +19,17 @@ module MAbbre
19
19
  super
20
20
  end
21
21
  end
22
+
23
+ ##
24
+ # call-seq:
25
+ # respond_to_missing?(name, include_all) => true or false
26
+ #
27
+ # Checks if this object responds to abbreviation +name+. The +include_all+ parameter is not used but it will
28
+ # be passed to +super+ if no suitable candidate is found.
29
+ #
30
+ # Returns +true+ if this object responds to +name+, or whatever +super+ returns otherwise.
31
+ def respond_to_missing?(name, include_all)
32
+ self.class.tracked_methods(MAbbre).one? {|m| m.to_s =~ /\A#{name}/ } or super
33
+ end
22
34
  end
23
35
  end
@@ -0,0 +1,36 @@
1
+ module MAbbre
2
+ ##
3
+ # Contains all compatibility patches that may be added to the environment depending on the current Ruby
4
+ # version/implementation. This module won't be defined in an environment were no patches were applied.
5
+ module Patch
6
+ ##
7
+ # Contains all patches related to the Object class. The methods contained within will only be defined if they are
8
+ # needed.
9
+ module ObjectMixin
10
+ ##
11
+ # call-seq:
12
+ # respond_to?(name, include_all = false) => true or false
13
+ #
14
+ # Passes +name+ and +include_all+ to +super+, and if +false+ is returned then #respond_to_missing? will be
15
+ # called.
16
+ #
17
+ # Returns +true+ if this object responds to +name+, and +false+ otherwise.
18
+ def respond_to?(name, include_all = false)
19
+ super or respond_to_missing?(name, include_all)
20
+ end
21
+
22
+ private
23
+
24
+ ##
25
+ # call-seq:
26
+ # respond_to_missing?(name, include_all) => false
27
+ #
28
+ # This is used as the base implementation of #respond_to_missing?.
29
+ #
30
+ # Returns +false+ irregardless of the value of +name+ and +include_all+.
31
+ def respond_to_missing?(_name, _include_all)
32
+ false
33
+ end
34
+ end
35
+ end
36
+ end
@@ -35,5 +35,5 @@
35
35
  module MAbbre
36
36
  ##
37
37
  # Current version of MAbbre.
38
- VERSION = "0.0.1"
38
+ VERSION = "0.0.2"
39
39
  end
data/lib/mabbre.rb CHANGED
@@ -1,2 +1,3 @@
1
+ require "mabbre/compatibility"
1
2
  require "mabbre/mixin"
2
3
  require "mabbre/version"
data/mabbre.gemspec CHANGED
@@ -8,8 +8,13 @@ Gem::Specification.new do |spec|
8
8
  spec.version = MAbbre::VERSION
9
9
  spec.authors = ["Gabriel de Oliveira"]
10
10
  spec.email = ["deoliveira.gab@gmail.com"]
11
- spec.summary = "Write a short summary. Required."
12
- spec.description = "Write a longer description. Optional."
11
+ spec.summary = "Enable shortened method names on classes and modules."
12
+ spec.description = <<-EOS.strip.gsub(/\n/, "").gsub(/\s{2,}/, " ")
13
+ MAbbre allows a group of methods in a Class or a
14
+ Module to be accessed using an abbreviated form.
15
+ These methods can be defined anywhere within a
16
+ hierarchy of inclusion and/or inheritance.
17
+ EOS
13
18
  spec.homepage = "https://github.com/gdeoliveira/mabbre"
14
19
  spec.license = "MIT"
15
20
 
@@ -17,5 +22,5 @@ Gem::Specification.new do |spec|
17
22
  spec.test_files = spec.files.grep(/^(test|spec|features)\//)
18
23
  spec.require_paths = ["lib"]
19
24
 
20
- spec.add_dependency "mtrack", "~> 1.1.0"
25
+ spec.add_dependency "mtrack", "~> 1.1"
21
26
  end
@@ -150,29 +150,6 @@ describe MAbbre::Mixin do
150
150
  :meth_11_extra, :meth_12_extra, :meth_13_extra,
151
151
  :meth_21_extra, :meth_22_extra, :meth_23_extra])
152
152
  end
153
-
154
- describe "instance" do
155
- subject { super_class.new }
156
-
157
- it "avoids calling ambiguous methods" do
158
- expect { subject.meth }.to raise_error(NoMethodError)
159
- expect { subject.meth_0 }.to raise_error(NoMethodError)
160
- expect { subject.meth_1 }.to raise_error(NoMethodError)
161
- expect { subject.meth_2 }.to raise_error(NoMethodError)
162
- end
163
-
164
- it "calls resolvable methods that can be abbreviated" do
165
- expect(subject.meth_01).to be(:meth_01_extra)
166
- expect(subject.meth_12).to be(:meth_12_extra)
167
- expect(subject.meth_23).to be(:meth_23_extra)
168
- end
169
-
170
- it "avoids calling resolvable methods that can't be abbreviated" do
171
- expect { subject.meth_00 }.to raise_error(NoMethodError)
172
- expect { subject.meth_10 }.to raise_error(NoMethodError)
173
- expect { subject.meth_20 }.to raise_error(NoMethodError)
174
- end
175
- end
176
153
  end
177
154
 
178
155
  context "sub class" do
@@ -188,6 +165,8 @@ describe MAbbre::Mixin do
188
165
  describe "instance" do
189
166
  subject { sub_class.new }
190
167
 
168
+ it { should_not respond_to(:meth, :meth_0, :meth_1, :meth_2, :meth_3) }
169
+
191
170
  it "avoids calling ambiguous methods" do
192
171
  expect { subject.meth }.to raise_error(NoMethodError)
193
172
  expect { subject.meth_0 }.to raise_error(NoMethodError)
@@ -196,6 +175,8 @@ describe MAbbre::Mixin do
196
175
  expect { subject.meth_3 }.to raise_error(NoMethodError)
197
176
  end
198
177
 
178
+ it { should respond_to(:meth_01, :meth_12, :meth_23, :meth_31) }
179
+
199
180
  it "calls resolvable methods that can be abbreviated" do
200
181
  expect(subject.meth_02).to be(:meth_02_extra)
201
182
  expect(subject.meth_13).to be(:meth_13_extra)
@@ -203,6 +184,8 @@ describe MAbbre::Mixin do
203
184
  expect(subject.meth_32).to be(:meth_32_extra)
204
185
  end
205
186
 
187
+ it { should_not respond_to(:meth_00, :meth_10, :meth_20, :meth_30) }
188
+
206
189
  it "avoids calling resolvable methods that can't be abbreviated" do
207
190
  expect { subject.meth_09 }.to raise_error(NoMethodError)
208
191
  expect { subject.meth_19 }.to raise_error(NoMethodError)
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+ require "mabbre/patch/object_mixin/respond_to_missing"
3
+
4
+ describe MAbbre::Patch::ObjectMixin do
5
+ subject do
6
+ dc = described_class
7
+ Class.new.instance_eval { include dc }.new
8
+ end
9
+
10
+ describe "#respond_to?" do
11
+ it "calls #respond_to_missing? at least once" do
12
+ expect(subject).to receive(:respond_to_missing?).with(:test_method, false).at_least(:once)
13
+ subject.respond_to? :test_method
14
+ end
15
+
16
+ it "calls #respond_to_missing? at most twice" do
17
+ expect(subject).to receive(:respond_to_missing?).with(:test_method, false).at_most(:twice)
18
+ subject.respond_to? :test_method
19
+ end
20
+ end
21
+
22
+ describe "#respond_to_missing?" do
23
+ it "returns false" do
24
+ expect(subject.send(:respond_to_missing?, :test_method, true)).to be(false)
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mabbre
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel de Oliveira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mtrack
@@ -16,15 +16,17 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0
19
+ version: '1.1'
20
20
  type: :runtime
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: 1.1.0
27
- description: Write a longer description. Optional.
26
+ version: '1.1'
27
+ description: MAbbre allows a group of methods in a Class or a Module to be accessed
28
+ using an abbreviated form. These methods can be defined anywhere within a hierarchy
29
+ of inclusion and/or inheritance.
28
30
  email:
29
31
  - deoliveira.gab@gmail.com
30
32
  executables: []
@@ -41,13 +43,16 @@ files:
41
43
  - README.md
42
44
  - Rakefile
43
45
  - lib/mabbre.rb
46
+ - lib/mabbre/compatibility.rb
44
47
  - lib/mabbre/extension.rb
45
48
  - lib/mabbre/interpreter.rb
46
49
  - lib/mabbre/mixin.rb
50
+ - lib/mabbre/patch/object_mixin/respond_to_missing.rb
47
51
  - lib/mabbre/version.rb
48
52
  - mabbre.gemspec
49
53
  - spec/.rubocop.yml
50
54
  - spec/lib/mabbre/mixin_spec.rb
55
+ - spec/lib/mabbre/patch/object_mixin/respond_to_missing_spec.rb
51
56
  - spec/lib/mabbre/version_spec.rb
52
57
  - spec/spec_helper.rb
53
58
  - tasks/console.rb
@@ -75,9 +80,10 @@ rubyforge_project:
75
80
  rubygems_version: 2.4.4
76
81
  signing_key:
77
82
  specification_version: 4
78
- summary: Write a short summary. Required.
83
+ summary: Enable shortened method names on classes and modules.
79
84
  test_files:
80
85
  - spec/.rubocop.yml
81
86
  - spec/lib/mabbre/mixin_spec.rb
87
+ - spec/lib/mabbre/patch/object_mixin/respond_to_missing_spec.rb
82
88
  - spec/lib/mabbre/version_spec.rb
83
89
  - spec/spec_helper.rb