forked from chef-boneyard/resource
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.rb
More file actions
57 lines (52 loc) · 1.25 KB
/
Copy pathexample.rb
File metadata and controls
57 lines (52 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Bar < ChefResource::Struct
property :x, Integer do
def self.default
20
end
end
end
class Foo < ChefResource::Struct
property :bar, Bar do
def self.default
{}
end
end
end
class X < ChefResource::Struct
property :foo, Foo do
def self.default
{}
end
end
end
x = X.new # X, parent=nil
foo = x.foo # X::Foo, parent=x, updates={}
bar = foo.bar # Foo::Bar, parent=foo, updates={}
bar.x # Bar::X.uncoerce(bar) -> bar.updates.fetch(:x) { Bar::X.default }
bar.x = 10 # bar.create do
# x = 10
# end
updates[:x] = X.coerce(x, bar, 10)
if bar.is_set?(:x)
end
if foo.is_set?(:bar)
end
if foo.is_set?()
# foo.updates[:bar] = bar
# x.updates[:foo] = foo
github = github
org = github.organizations.first
repo = org.repositories.first
repo.update do
b = 10
c = 20
end
# Resource
# new(parent, ...): create Resource
# create_transaction()
x # X, parent=nil, updates={ foo: { bar: { x: 10 } } }
foo # X::Foo, parent=x
bar # Foo::Bar, parent=foo
# x is a transaction. x.foo and x.bar are transaction children, which simply
# update changes to their parent as they are made. A method (like sort) may
# create a temporary transaction on foo or bar, however.