cockpit 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,7 @@ module Cockpit
17
17
  end
18
18
 
19
19
  define_method "#{key}?" do
20
- send(:cockpit).has_key?(key)
20
+ send(:cockpit).present?(key)
21
21
  end
22
22
  end
23
23
  end
@@ -4,7 +4,7 @@ module Cockpit
4
4
 
5
5
  def initialize(settings, method, *args, &block)
6
6
  @settings = settings
7
- process(method, *args, &block)
7
+ _process(method, *args, &block)
8
8
  end
9
9
 
10
10
  def value
@@ -15,17 +15,46 @@ module Cockpit
15
15
  settings[key] = x
16
16
  end
17
17
 
18
- def process(method, *args, &block)
19
- node = method.to_s
20
-
18
+ def to_i
19
+ value.to_i
20
+ end
21
+
22
+ def to_s
23
+ value.to_s
24
+ end
25
+
26
+ def to_f
27
+ value.to_f
28
+ end
29
+
30
+ def nil?
31
+ value.nil?
32
+ end
33
+
34
+ def empty?
35
+ value.empty?
36
+ end
37
+
38
+ def blank?
39
+ value.blank?
40
+ end
41
+
42
+ def _process(method, *args, &block)
43
+ method = method.to_s
44
+ node = method.dup
45
+
21
46
  boolean = !!(node =~ /\?$/)
22
47
  node.gsub!(/\?/, "") if boolean
23
48
 
24
49
  set = !!(node =~ /=$/)
25
50
  node.gsub!("=", "") if set
26
51
 
52
+ new_key = "#{key}.#{node}"
53
+
54
+ return value.send(method) if key && !settings.has_key?(new_key) && value.respond_to?(method)
55
+
27
56
  if key
28
- @key = "#{key}.#{node}"
57
+ @key = new_key
29
58
  else
30
59
  @key = node
31
60
  end
@@ -40,7 +69,7 @@ module Cockpit
40
69
  end
41
70
 
42
71
  def method_missing(method, *args, &block)
43
- process(method, *args, &block)
72
+ _process(method, *args, &block)
44
73
  end
45
74
  end
46
75
  end
@@ -172,11 +172,20 @@ module Cockpit
172
172
  @spec ||= self.class.spec(self.name, self.record_type)
173
173
  end
174
174
 
175
+ def present?(key)
176
+ has_key?(key) && !empty?(key)
177
+ end
178
+
179
+ def empty?(key)
180
+ value = self[key]
181
+ value.respond_to?(:empty?) ? value.empty? : !value
182
+ end
183
+
175
184
  protected
176
185
 
177
186
  def method_missing(method, *args, &block)
178
187
  if method.to_s =~ /(\w+)\?$/
179
- has_key?($1)
188
+ present?($1)
180
189
  elsif has_key?(method)
181
190
  Cockpit::Scope.new(self, method, *args, &block)
182
191
  else
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cockpit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lance Pollard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-18 00:00:00 -05:00
18
+ date: 2010-09-20 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency