s2p 0.0.1
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.
- checksums.yaml +7 -0
- data/lib/s2p/component.rb +63 -0
- data/lib/s2p/contractor.rb +93 -0
- data/lib/s2p/version.rb +3 -0
- metadata +42 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d80c07291bbd7f13749d4aa067ea27b9c75bfe03409f580e74f96d986c7ca0eb
|
4
|
+
data.tar.gz: 3ae7cc86f20a15b99cd34afa498c23b48917efa7832213651bbc103f46ab0b46
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33b24855f255d5ef60a5c0e75529f0684d19b4ca69205aa241d1b2d700bac41cdea6f627b58eb9a49c90d97721d1921839bbfaf26b515dfc820e4e77086866ed
|
7
|
+
data.tar.gz: 6d1a585cd952aca44c726c111b51f1dd690808dbae60d565f87b46c7abae944c8703c820df7f98f05368c8fb4f49f5d22b8f5ac59249e401eac8340e2f26e7ab
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module S2P
|
2
|
+
module Component
|
3
|
+
def self.renderer = ApplicationController
|
4
|
+
def self.helpers = self.renderer.helpers
|
5
|
+
|
6
|
+
class Buffer
|
7
|
+
def initialize(string)
|
8
|
+
@string = string.html_safe
|
9
|
+
end
|
10
|
+
|
11
|
+
def +(other) = self.class.new(@string + other.to_s)
|
12
|
+
def to_s = @string
|
13
|
+
end
|
14
|
+
|
15
|
+
module Component
|
16
|
+
module ClassMethods
|
17
|
+
def [](*a, **o, &b) = new(*a, **o, &b)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.included(base) = base.extend(ClassMethods)
|
21
|
+
|
22
|
+
def t(template, **locals) = renderer.render(inline: template, locals:)
|
23
|
+
|
24
|
+
def t!(template, **locals) = renderer.render(template, locals:, layout: nil)
|
25
|
+
|
26
|
+
def x = helpers.tag
|
27
|
+
|
28
|
+
def o(&block) = block.binding.receiver.capture(&block)
|
29
|
+
|
30
|
+
def +(other) = Buffer.new(to_s + other.to_s)
|
31
|
+
|
32
|
+
def accepts_slot(block) = @_slot = block
|
33
|
+
|
34
|
+
def capture(&block) = block.call.to_s.html_safe
|
35
|
+
|
36
|
+
def default_template_name = "shared/#{self.class.name.underscore}"
|
37
|
+
|
38
|
+
def helpers = LittleWheels.helpers
|
39
|
+
|
40
|
+
def renderer = LittleWheels.renderer
|
41
|
+
|
42
|
+
def render_in(context) = context.render(:inline => to_html)
|
43
|
+
|
44
|
+
def to_s = to_html
|
45
|
+
|
46
|
+
def slot
|
47
|
+
context = @_slot.binding.receiver
|
48
|
+
|
49
|
+
context.capture { @_slot.call.to_s }
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_html
|
53
|
+
helpers.capture do
|
54
|
+
if self.class.const_defined?(:TEMPLATE)
|
55
|
+
t(self.class.const_get(:TEMPLATE), c: self, x: self.x )
|
56
|
+
else
|
57
|
+
t!(default_template_name, c: self, x: self.x )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module S2P
|
2
|
+
class Contractor
|
3
|
+
def self.for(description)
|
4
|
+
new(description)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.[](description)
|
8
|
+
self.for(description)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.disable_enforcement
|
12
|
+
@conditions_disabled = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.conditions_disabled?
|
16
|
+
!!( @conditions_disabled || ENV["SKIP_CONTRACT_ENFORCEMENT"] )
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(description)
|
20
|
+
@description = description
|
21
|
+
@assumptions = []
|
22
|
+
@assurances = []
|
23
|
+
@observations = {}
|
24
|
+
@context = ""
|
25
|
+
end
|
26
|
+
|
27
|
+
def watches(name, &b)
|
28
|
+
@observations[name] = { action: b }
|
29
|
+
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_reader :observations
|
34
|
+
|
35
|
+
def acknowledges(context)
|
36
|
+
@context << "[#{context}]"
|
37
|
+
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def broken(message)
|
42
|
+
raise message unless self.class.conditions_disabled?
|
43
|
+
end
|
44
|
+
|
45
|
+
def __fixme__
|
46
|
+
broken("Not implemented yet")
|
47
|
+
end
|
48
|
+
|
49
|
+
def assumes(description, &b)
|
50
|
+
@assumptions << [description, b]
|
51
|
+
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def ensures(description, &b)
|
56
|
+
@assurances << [description, b]
|
57
|
+
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
def work(*)
|
62
|
+
return yield(*) if self.class.conditions_disabled?
|
63
|
+
|
64
|
+
@assumptions.each do |description, condition|
|
65
|
+
if @context != ""
|
66
|
+
fail "Failed expectation: [when #{@context}] #{description} (in #{@description})" unless condition.call(*)
|
67
|
+
else
|
68
|
+
fail "Failed expectation: #{description} (in #{@description})" unless condition.call(*)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
@observations.each do |message, diff|
|
73
|
+
diff[:before] = diff[:action].call
|
74
|
+
end
|
75
|
+
|
76
|
+
result = yield(*)
|
77
|
+
|
78
|
+
@observations.each do |message, diff|
|
79
|
+
diff[:after] = diff[:action].call
|
80
|
+
end
|
81
|
+
|
82
|
+
@assurances.each do |description, condition|
|
83
|
+
if @context != ""
|
84
|
+
fail "Failed expectation: #{@context} #{description} (in #{@description})" unless condition.call(result, observations)
|
85
|
+
else
|
86
|
+
fail "Failed expectation: #{description} (in #{@description})" unless condition.call(result, observations)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
result
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/s2p/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: s2p
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregory Brown
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-02-01 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: Experimental dev utilies from skillstopractice.com. Will eventually find
|
13
|
+
homes in their own gems if they pan out.
|
14
|
+
email: gregory@practicingdeveloper.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/s2p/component.rb
|
20
|
+
- lib/s2p/contractor.rb
|
21
|
+
- lib/s2p/version.rb
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.6.2
|
40
|
+
specification_version: 4
|
41
|
+
summary: Experimental dev utilies from skillstopractice.com
|
42
|
+
test_files: []
|