recordx 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/recordx.rb +36 -6
  2. metadata +1 -1
data/lib/recordx.rb CHANGED
@@ -4,8 +4,23 @@
4
4
 
5
5
  class RecordX
6
6
 
7
- def initialize(callerx, id, h={})
7
+ class RXHash < Hash
8
+ def initialize(callerx)
9
+ super()
10
+ @callerx = callerx
11
+ end
12
+
13
+ def []=(name, val)
14
+ unless @callerx.send(name.to_sym) == val then
15
+ @callerx.send((name.to_s + '=').to_sym, val)
16
+ end
17
+ super(name, val)
18
+ end
19
+ end
20
+
21
+ def initialize(h={}, callerx=nil, id=nil )
8
22
  @callerx, @id = callerx, id
23
+ @h = RXHash.new(self)
9
24
  h.each {|name,val| attr_accessor2(name.to_s, val) }
10
25
  end
11
26
 
@@ -16,10 +31,25 @@ class RecordX
16
31
  end
17
32
 
18
33
  def attr_accessor2(name,val=nil)
19
- self.instance_eval "def #{name}=(s)\n @#{name} = s.to_s\n\
20
- @callerx.update(@id, #{name}: s.to_s)\n end\n\
21
- def #{name}() @#{name} end\n\
22
- @#{name} = '#{val}'"
34
+ self.instance_eval %Q{
35
+ def #{name}=(s)
36
+ @#{name} = s.to_s
37
+ unless @h[:#{name}] == s.to_s then
38
+ @h[:#{name}] = s.to_s
39
+ @callerx.update(@id, #{name}: s.to_s) if @callerx
40
+ end
41
+ end
42
+
43
+ def #{name}()
44
+ @#{name}
45
+ end
46
+
47
+ @#{name} = '#{val}'}
48
+ end
49
+
50
+ def h()
51
+ @h
23
52
  end
24
53
 
25
- end
54
+ alias to_h h
55
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: recordx
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson