ztk 1.6.30 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWQxOGYzNTBiMmJmZjI0ZTM4YzZlZjRlMGQ0NDMzODJmNmQ0MDBjYQ==
4
+ NDlkMjkwMjJjNmFmN2I1YzBhMmUxOWUyYTU2NmMzYTM5OGQxOGE0Mg==
5
5
  data.tar.gz: !binary |-
6
- YWQzMjAzOTZjYWQzY2U4YTgwYmI3ZjY2Mjg1ZmRhMzdkM2JiMTZkMw==
6
+ ZGQ1ZTAxZjExYzkwOTA4MjYzZGQ2YTU5MjNmMTgxYmY3NTQ3MmQ1ZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjQ1MmU3Mzk4ZDVkZjlmMDI3MGQ5MTE5ZmRjNzQ4NjJjZDJmN2E3MzVkZWUw
10
- MzcyMmRiNzI5YjZhOTlkMWUxMWM1NDcxMzA0MDNjMTdiYTY5NzgwOWNiODA1
11
- MThhNzI0ZDg3YjZhMDE3NmU0YTBiOTQ2OTI4MzE3ZTIxMDVmNmQ=
9
+ YzhjMDg1MTQ1NWRjNmI2YWY5Y2U0YjQxOGI3ZjE5OGNiNTgwMjkxY2UxODdh
10
+ YWEwZDIwYzJmNWQxNTdhY2U5NzMyZmZhN2IzNTQ1MWMwMjZhNWYwMWVlODg1
11
+ ZjBmZjJmZDVmYjJlNTBiMDFjYzFlNTU3NTJmOTUxMTQ3MTZjMWI=
12
12
  data.tar.gz: !binary |-
13
- NDQ5OWVlNGYzOWI2MmI5NzYyOTY1ZmRkYTk3MTM5MTMwMzljMjA3MjNlYzUx
14
- MzBmZWYyNmUwZTk5MWVmNWZjMmFmMjM0NWE5MDFiNjQ2MzFiYWNiMjE5N2Jl
15
- NTk5ZWE2OTNjMjBjMGI0OTlkMmYxODdmMDNlZDU4MDY4ZDllOGQ=
13
+ MGRmMzE2NjdjYWNlMjNmY2VmYzc3MTJkNDJmN2NmZmZmNTAwNjQ1MThkZDZl
14
+ MzE0MWM0OTM1YWRhMzNiMzI5OWQ1YjU1YTQxYjQ0OWY2Zjk5Y2ZmNjE0Y2Fi
15
+ OGYwZWU2M2UzNzZlOWMwZDI5NTk2NjQwNDE3ZGFjYWViYzUyOWE=
data/lib/ztk/dsl/base.rb CHANGED
@@ -154,12 +154,21 @@ module ZTK::DSL
154
154
  self.id = (id || self.class.next_id)
155
155
  self.class.dataset << self
156
156
 
157
- block_given? and ((block.arity < 1) ? instance_eval(&block) : block.call(self))
157
+ do_block(&block)
158
+ end
159
+
160
+ def do_block(&block)
161
+ if block_given?
162
+ if (block.arity < 1)
163
+ instance_eval(&block)
164
+ else
165
+ block.call(self)
166
+ end
167
+ end
158
168
 
159
- primary_key_count = self.class.dataset.count do |d|
160
- d.id == self.id
169
+ if (self.class.dataset.count{ |data| (data.id == self.id) } > 1)
170
+ raise StandardError, "Primary key '#{self.id}' already exists!"
161
171
  end
162
- raise StandardError, "Primary key '#{self.id}' already exists!" if (primary_key_count > 1)
163
172
  end
164
173
 
165
174
  # Instance Inspect
@@ -188,7 +197,7 @@ module ZTK::DSL
188
197
  def inspect
189
198
  details = Array.new
190
199
  details << "count=#{self.all.count}" if self.all.count > 0
191
- "#<#{self.class.to_s}:#{self.id} #{details.join(', ')}>"
200
+ "#<#{self.to_s} #{details.join(', ')}>"
192
201
  end
193
202
 
194
203
  end
@@ -23,7 +23,11 @@ module ZTK::DSL::Core::Actions
23
23
  end
24
24
 
25
25
  def first(*args)
26
- find(*args).first
26
+ if args.count == 0
27
+ all.first
28
+ else
29
+ find(*args).first
30
+ end
27
31
  end
28
32
 
29
33
  def count
@@ -35,7 +35,13 @@ module ZTK::DSL::Core
35
35
 
36
36
  send(:define_method, "#{key}=") do |value|
37
37
  attributes[key] = value
38
+ value
38
39
  end
40
+
41
+ self.class.send(:define_method, "find_by_#{key}") do |value|
42
+ all.select{ |object| (object.send(key) == value) }
43
+ end
44
+
39
45
  end
40
46
 
41
47
  end
data/lib/ztk/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module ZTK
2
2
 
3
3
  # ZTK Version String
4
- VERSION = "1.6.30"
4
+ VERSION = "1.7.0"
5
5
 
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ztk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.30
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Patten
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-13 00:00:00.000000000 Z
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport