striuct 0.0.11.1 → 0.1.7

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.
@@ -0,0 +1,72 @@
1
+ class Striuct; module Subclassable
2
+ # @group Struct+ Safety
3
+
4
+ # see self.class.*args
5
+ delegate_class_methods :restrict?, :has_conditions?, :inference?
6
+
7
+ # @param [Symbol, String] name
8
+ # @param [Object] *values - no argument and use own
9
+ # passed under any condition
10
+ def sufficient?(name, value=self[name])
11
+ self.class.sufficient? name, value, self
12
+ end
13
+
14
+ alias_method :accept?, :sufficient?
15
+ alias_method :valid?, :sufficient?
16
+
17
+ # all members passed under any condition
18
+ def strict?
19
+ each_pair.all?{|name, value|sufficient? name, value}
20
+ end
21
+
22
+ # freezed, fixed familar members, all members passed any condition
23
+ def secure?
24
+ (frozen? || lock?) && self.class.closed? && strict?
25
+ end
26
+
27
+ # @overload lock(key)
28
+ # lock a setter for key
29
+ # @param [Symbol, String, Fixnum] key
30
+ # @overload lock(true)
31
+ # lock setters for all members
32
+ # @param [true] true
33
+ # @return [self]
34
+ def lock(key=true)
35
+ raise "can't modify frozen #{self.class}" if frozen?
36
+
37
+ if key.equal? true
38
+ names.each do |name|
39
+ @locks[name] = true
40
+ end
41
+ else
42
+ __subscript__(key){|name|@locks[name] = true}
43
+ end
44
+
45
+ self
46
+ end
47
+
48
+ # @see #lock
49
+ def lock?(key=true)
50
+ if key.equal? true
51
+ names.all?{|name|@locks[name]}
52
+ else
53
+ __subscript__(key){|name|@locks[name]} || false
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def unlock(key=true)
60
+ raise "can't modify frozen #{self.class}" if frozen?
61
+
62
+ if key.equal? true
63
+ @locks.clear
64
+ else
65
+ __subscript__(key){|name|@locks.delete name}
66
+ end
67
+
68
+ self
69
+ end
70
+
71
+ # @endgroup
72
+ end; end
@@ -0,0 +1,14 @@
1
+ autoload :YAML, 'yaml'
2
+
3
+ class Striuct; module Subclassable
4
+ # @group for YAML
5
+
6
+ # @return [String]
7
+ def to_yaml
8
+ YAML.__id__ # for autoload
9
+ klass = Struct.new(*members)
10
+ klass.new(*values).to_yaml
11
+ end
12
+
13
+ # @endgroup
14
+ end; end
@@ -1,4 +1,4 @@
1
1
  class Striuct
2
- VERSION = '0.0.11.1'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  Version = VERSION
4
- end
4
+ end
data/lib/striuct.rb CHANGED
@@ -1,4 +1,5 @@
1
- require_relative 'striuct/version'
2
- require_relative 'striuct/core'
1
+ # Copyright (C) 2011 Kenichi Kamiya
2
+
3
+ require_relative 'striuct/frame'
3
4
 
4
5
  StrictStruct = Striuct