ghost_dog 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -109,7 +109,7 @@ class MyModel < ActiveRecord::Base
109
109
  raise ArgumentError, "Wrong number of arguments (#{args.length} for #{columns_to_find_by.length})"
110
110
  end
111
111
 
112
- where(Hash[columns_to_find_by.zip(args)])
112
+ where(Hash[columns_to_find_by.zip(args)]).first
113
113
  end
114
114
  end
115
115
  end
data/lib/ghost_dog.rb CHANGED
@@ -20,8 +20,10 @@ module GhostDog
20
20
  end
21
21
 
22
22
  def _klass_where_ghost_method_definitions_are
23
- if self.class == Class
24
- self.singleton_class
23
+ if self.class.is_a?(Class)
24
+ singleton_class.extend(ClassMethods) unless singleton_class.is_a?(ClassMethods)
25
+
26
+ singleton_class
25
27
  else
26
28
  self.class
27
29
  end
@@ -47,17 +49,6 @@ module GhostDog
47
49
  super
48
50
  end
49
51
  end
50
-
51
- def inherited(child)
52
- _setup_ghost_dog_singleton_class_inheritance(child)
53
- super
54
- end
55
-
56
- def _setup_ghost_dog_singleton_class_inheritance(child)
57
- if singleton_class.respond_to?(:_setup_ghost_dog_inheritance, :include_private)
58
- singleton_class.send(:_setup_ghost_dog_inheritance, child.singleton_class)
59
- end
60
- end
61
52
  end
62
53
 
63
54
  module ClassMethods
@@ -70,16 +61,15 @@ module GhostDog
70
61
  private
71
62
 
72
63
  def _ghost_method_definitions
73
- @_ghost_methods ||= []
74
- end
75
-
76
- def inherited(child)
77
- _setup_ghost_dog_inheritance(child)
78
- super
79
- end
80
-
81
- def _setup_ghost_dog_inheritance(child)
82
- child.instance_variable_set('@_ghost_methods', _ghost_method_definitions)
64
+ @_ghost_methods ||= [].tap do |defs|
65
+ klasses_that_might_have_ghost_methods = []
66
+ klasses_that_might_have_ghost_methods << superclass if defined?(superclass)
67
+ klasses_that_might_have_ghost_methods.concat(included_modules)
68
+
69
+ klasses_that_might_have_ghost_methods.select { |k| k.respond_to?(:_ghost_method_definitions, :include_private) }.each do |k|
70
+ defs.concat(k.send(:_ghost_method_definitions).dup)
71
+ end
72
+ end
83
73
  end
84
74
  end
85
75
  end
@@ -1,3 +1,3 @@
1
1
  module GhostDog
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -27,6 +27,39 @@ describe GhostDog do
27
27
  end
28
28
  end
29
29
 
30
+ context 'module responder' do
31
+ module MinimalModule
32
+ include GhostDog
33
+
34
+ ghost_method /^tell_me_(.+)$/ do |what_to_tell|
35
+ what_to_tell.gsub('_', ' ')
36
+ end
37
+ end
38
+
39
+ class MinimalImpl
40
+ include MinimalModule
41
+ end
42
+
43
+ let(:obj) { MinimalImpl.new }
44
+ subject { obj }
45
+ its(:tell_me_hello_world) { should == "hello world" }
46
+
47
+ context 'singleton module' do
48
+ module SingletonModule
49
+ class << self
50
+ include GhostDog
51
+
52
+ ghost_method /^hello_(.+)$/ do |name|
53
+ name.gsub('_', ' ')
54
+ end
55
+ end
56
+ end
57
+
58
+ subject { SingletonModule }
59
+ its(:hello_andrew_my_friend) { should == "andrew my friend" }
60
+ end
61
+ end
62
+
30
63
  context 'class level responder' do
31
64
  class ClassLevel
32
65
  class << self
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghost_dog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Andrew Warner
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-05-13 00:00:00.000000000 Z
12
+ date: 2013-12-26 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rspec
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: pry
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ! '>='
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ! '>='
67
76
  - !ruby/object:Gem::Version
@@ -93,27 +102,29 @@ files:
93
102
  homepage: ''
94
103
  licenses:
95
104
  - MIT
96
- metadata: {}
97
105
  post_install_message:
98
106
  rdoc_options: []
99
107
  require_paths:
100
108
  - lib
101
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
102
111
  requirements:
103
112
  - - ! '>='
104
113
  - !ruby/object:Gem::Version
105
114
  version: '0'
106
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
107
117
  requirements:
108
118
  - - ! '>='
109
119
  - !ruby/object:Gem::Version
110
120
  version: '0'
111
121
  requirements: []
112
122
  rubyforge_project:
113
- rubygems_version: 2.0.3
123
+ rubygems_version: 1.8.24
114
124
  signing_key:
115
- specification_version: 4
125
+ specification_version: 3
116
126
  summary: Making method_missing easier since 2013
117
127
  test_files:
118
128
  - spec/lib/ghost_dog_spec.rb
119
129
  - spec/spec_helper.rb
130
+ has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YWJkODQ1MWVhYTc1NzYyZjdlODNjZjc3YjFjYTQyODJlMjYzNDExOA==
5
- data.tar.gz: !binary |-
6
- YWJhMzMxMDdkMDZhMjAwZDEwYjRlZjcxNzFhMWNiNzk1Mjk1YTYxMA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YTBiMGUzOGEzZWVlMGM2ZDhhZWU4MTg0NTNjMjcyYjE1NWIwYjVlY2RmMDYx
10
- MTgwYjg2NTgzNjQyNGI3MWY2NmYwOWIyOGE0ZGZjZjg1M2M1NDU2MjA1NzJm
11
- NzQ3ZDZkYjk2NDQ0ODk5ZDIwNTQ1YjI5ZDg3ODU1ZmQwMTI1MTI=
12
- data.tar.gz: !binary |-
13
- MmYzYTlmNGY0YTljYTliODcxNDM2YWI4YzZlYzFiNjdkMmIzZDBiYzYxMzc3
14
- ZDcyYTc5ZDQyMWQzM2RjMDY4ZTc3OTRjOWM4NDU5M2YzYTViZjA4ZTBhMjFk
15
- OTU1ZTUwYTIzMjM0MTQwYjNmMjRiM2Y4MzJjOWVjNTZhYzc0NjA=