cistern 2.2.3 → 2.2.4
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 +4 -4
- data/.travis.yml +4 -4
- data/lib/cistern/attributes.rb +62 -61
- data/lib/cistern/client.rb +30 -24
- data/lib/cistern/collection.rb +15 -16
- data/lib/cistern/coverage.rb +7 -5
- data/lib/cistern/data/hash.rb +5 -7
- data/lib/cistern/data/redis.rb +7 -9
- data/lib/cistern/data.rb +2 -2
- data/lib/cistern/formatter/awesome_print.rb +1 -1
- data/lib/cistern/formatter/default.rb +2 -2
- data/lib/cistern/formatter/formatador.rb +3 -3
- data/lib/cistern/hash.rb +3 -3
- data/lib/cistern/mock.rb +2 -2
- data/lib/cistern/model.rb +10 -10
- data/lib/cistern/request.rb +2 -2
- data/lib/cistern/service.rb +2 -2
- data/lib/cistern/singular.rb +2 -5
- data/lib/cistern/string.rb +6 -6
- data/lib/cistern/timeout.rb +3 -3
- data/lib/cistern/version.rb +1 -1
- data/lib/cistern/wait_for.rb +4 -4
- data/lib/cistern.rb +5 -6
- data/spec/client_spec.rb +8 -9
- data/spec/collection_spec.rb +18 -18
- data/spec/dirty_spec.rb +9 -9
- data/spec/formatter_spec.rb +14 -14
- data/spec/hash_spec.rb +17 -17
- data/spec/mock_data_spec.rb +21 -22
- data/spec/model_spec.rb +76 -76
- data/spec/request_spec.rb +8 -8
- data/spec/singular_spec.rb +7 -8
- data/spec/spec_helper.rb +3 -3
- data/spec/wait_for_spec.rb +7 -8
- metadata +2 -2
data/lib/cistern/collection.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Cistern::Collection
|
2
|
-
|
3
2
|
BLACKLISTED_ARRAY_METHODS = [
|
4
3
|
:compact!, :flatten!, :reject!, :reverse!, :rotate!, :map!,
|
5
4
|
:shuffle!, :slice!, :sort!, :sort_by!, :delete_if,
|
@@ -17,31 +16,31 @@ module Cistern::Collection
|
|
17
16
|
attr_accessor :records, :loaded, :service
|
18
17
|
|
19
18
|
module ClassMethods
|
20
|
-
def model(new_model=nil)
|
19
|
+
def model(new_model = nil)
|
21
20
|
@_model ||= new_model
|
22
21
|
end
|
23
22
|
|
24
|
-
def service_method(name=nil)
|
23
|
+
def service_method(name = nil)
|
25
24
|
@_service_method ||= name
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
|
28
|
+
alias_method :build, :initialize
|
30
29
|
|
31
30
|
def initialize(attributes = {})
|
32
31
|
merge_attributes(attributes)
|
33
32
|
end
|
34
33
|
|
35
|
-
def all(_={})
|
36
|
-
|
34
|
+
def all(_ = {})
|
35
|
+
fail NotImplementedError
|
37
36
|
end
|
38
37
|
|
39
|
-
def create(attributes={})
|
40
|
-
|
38
|
+
def create(attributes = {})
|
39
|
+
new(attributes).save
|
41
40
|
end
|
42
41
|
|
43
|
-
def get(
|
44
|
-
|
42
|
+
def get(_identity)
|
43
|
+
fail NotImplementedError
|
45
44
|
end
|
46
45
|
|
47
46
|
def clear
|
@@ -58,7 +57,7 @@ module Cistern::Collection
|
|
58
57
|
|
59
58
|
# @api private
|
60
59
|
def load_records
|
61
|
-
|
60
|
+
all unless loaded
|
62
61
|
end
|
63
62
|
|
64
63
|
# Should be called within #all to load records into the collection
|
@@ -76,12 +75,12 @@ module Cistern::Collection
|
|
76
75
|
|
77
76
|
def new(attributes = {})
|
78
77
|
unless attributes.is_a?(::Hash)
|
79
|
-
|
78
|
+
fail(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}"))
|
80
79
|
end
|
81
80
|
model.new(
|
82
81
|
{
|
83
|
-
:
|
84
|
-
:
|
82
|
+
collection: self,
|
83
|
+
service: service
|
85
84
|
}.merge(attributes)
|
86
85
|
)
|
87
86
|
end
|
@@ -94,7 +93,7 @@ module Cistern::Collection
|
|
94
93
|
|
95
94
|
def to_a
|
96
95
|
load_records
|
97
|
-
|
96
|
+
records || []
|
98
97
|
end
|
99
98
|
|
100
99
|
def respond_to?(method, include_private = false)
|
@@ -104,7 +103,7 @@ module Cistern::Collection
|
|
104
103
|
def ==(comparison_object)
|
105
104
|
comparison_object.equal?(self) ||
|
106
105
|
(comparison_object.is_a?(self.class) &&
|
107
|
-
comparison_object.to_a ==
|
106
|
+
comparison_object.to_a == to_a)
|
108
107
|
end
|
109
108
|
|
110
109
|
protected
|
data/lib/cistern/coverage.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module Cistern::Coverage
|
2
|
-
|
3
2
|
unless Kernel.respond_to? :caller_locations
|
4
3
|
abort <<-ABORT
|
5
4
|
Cannot enable Cistern coverage reporting
|
6
5
|
|
7
|
-
Your ruby version ruby is: #{
|
6
|
+
Your ruby version ruby is: #{begin
|
7
|
+
RUBY_VERSION
|
8
|
+
rescue
|
9
|
+
'unknown'
|
10
|
+
end}
|
8
11
|
`Kernel` does not have the required method `caller_locations`
|
9
12
|
|
10
13
|
Try a newer ruby (should be > 2.0)
|
@@ -18,17 +21,16 @@ Try a newer ruby (should be > 2.0)
|
|
18
21
|
call = nil
|
19
22
|
|
20
23
|
# seek to the first entry from within `file`
|
21
|
-
while(call = enum.next)
|
24
|
+
while (call = enum.next)
|
22
25
|
break if call.path.end_with? file
|
23
26
|
end
|
24
27
|
|
25
28
|
# seek to the first entry thats not within `file`
|
26
|
-
while(call = enum.next)
|
29
|
+
while (call = enum.next)
|
27
30
|
break unless call.path.end_with? file
|
28
31
|
end
|
29
32
|
|
30
33
|
# the call location that called in to `file`
|
31
34
|
call
|
32
35
|
end
|
33
|
-
|
34
36
|
end
|
data/lib/cistern/data/hash.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Cistern::Data::Hash
|
2
2
|
Cistern::Data.backends[:hash] = self
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@hash =
|
4
|
+
def initialize(_options = {}, &default)
|
5
|
+
@hash = {}
|
6
6
|
@default = default
|
7
7
|
end
|
8
8
|
|
@@ -16,7 +16,7 @@ class Cistern::Data::Hash
|
|
16
16
|
hash.store(key, *args)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
alias_method :[]=, :store
|
20
20
|
|
21
21
|
def fetch(key, *args)
|
22
22
|
assign_default(key)
|
@@ -24,15 +24,13 @@ class Cistern::Data::Hash
|
|
24
24
|
hash.fetch(key, *args)
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
alias_method :[], :fetch
|
28
28
|
|
29
29
|
protected
|
30
30
|
|
31
31
|
attr_reader :hash, :default
|
32
32
|
|
33
33
|
def assign_default(key)
|
34
|
-
if !hash.key?(key) && default
|
35
|
-
default.call(hash, key)
|
36
|
-
end
|
34
|
+
default.call(hash, key) if !hash.key?(key) && default
|
37
35
|
end
|
38
36
|
end
|
data/lib/cistern/data/redis.rb
CHANGED
@@ -11,17 +11,17 @@ class Cistern::Data::Redis
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
class << self
|
15
|
+
attr_writer :marshal
|
16
16
|
end
|
17
17
|
|
18
|
-
def initialize(options={}, &block)
|
18
|
+
def initialize(options = {}, &block)
|
19
19
|
@client = options[:client] || ::Redis.new
|
20
20
|
@default = block
|
21
21
|
end
|
22
22
|
|
23
23
|
def clear
|
24
|
-
unless (keys = client.keys(
|
24
|
+
unless (keys = client.keys('*')).empty?
|
25
25
|
client.del(*keys)
|
26
26
|
end
|
27
27
|
end
|
@@ -32,7 +32,7 @@ class Cistern::Data::Redis
|
|
32
32
|
client.set(key, Cistern::Data::Redis.marshal.dump(value), *args)
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
alias_method :[]=, :store
|
36
36
|
|
37
37
|
def fetch(key, *args)
|
38
38
|
assign_default(key)
|
@@ -40,15 +40,13 @@ class Cistern::Data::Redis
|
|
40
40
|
Cistern::Data::Redis.marshal.load(client.get(key, *args))
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
alias_method :[], :fetch
|
44
44
|
|
45
45
|
protected
|
46
46
|
|
47
47
|
attr_reader :client, :default
|
48
48
|
|
49
49
|
def assign_default(key)
|
50
|
-
if client.keys(key).empty? && default
|
51
|
-
default.call(client, key)
|
52
|
-
end
|
50
|
+
default.call(client, key) if client.keys(key).empty? && default
|
53
51
|
end
|
54
52
|
end
|
data/lib/cistern/data.rb
CHANGED
@@ -16,7 +16,7 @@ module Cistern::Data
|
|
16
16
|
|
17
17
|
module ClassMethods
|
18
18
|
def data
|
19
|
-
@data ||= Cistern::Data.backend(*storage) { |d,k| d[k] = [] }
|
19
|
+
@data ||= Cistern::Data.backend(*storage) { |d, k| d[k] = [] }
|
20
20
|
end
|
21
21
|
|
22
22
|
def reset!
|
@@ -25,7 +25,7 @@ module Cistern::Data
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def clear!
|
28
|
-
|
28
|
+
data.clear
|
29
29
|
end
|
30
30
|
|
31
31
|
def store_in(*args)
|
@@ -27,7 +27,7 @@ module AwesomePrint::Cistern
|
|
27
27
|
# Format Cistern::Model
|
28
28
|
#------------------------------------------------------------------------------
|
29
29
|
def awesome_cistern_model(object)
|
30
|
-
data = object.attributes.keys.inject({}){|r,k| r.merge(k => object.send(k))}
|
30
|
+
data = object.attributes.keys.inject({}) { |r, k| r.merge(k => object.send(k)) }
|
31
31
|
"#{object} " << awesome_hash(data)
|
32
32
|
end
|
33
33
|
|
@@ -12,11 +12,11 @@ module Cistern::Formatter::Default
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def format_model(model)
|
15
|
-
"#{model
|
15
|
+
"#{model} #{model.attributes.inspect}"
|
16
16
|
end
|
17
17
|
|
18
18
|
def format_collection(collection)
|
19
|
-
"#{collection
|
19
|
+
"#{collection} #{collection.attributes.inspect} records=[#{collection.records.map { |m| format_model(m) }.join(', ')}]"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -29,14 +29,14 @@ module Cistern::Formatter::Formatador
|
|
29
29
|
Thread.current[:formatador].indent do
|
30
30
|
unless collection.class.attributes.empty?
|
31
31
|
data << "#{Thread.current[:formatador].indentation}"
|
32
|
-
data << collection.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
|
32
|
+
data << collection.class.attributes.map { |attribute| "#{attribute}=#{send(attribute).inspect}" }.join(",\n#{Thread.current[:formatador].indentation}")
|
33
33
|
data << "\n"
|
34
34
|
end
|
35
35
|
data << "#{Thread.current[:formatador].indentation}["
|
36
36
|
unless collection.empty?
|
37
37
|
data << "\n"
|
38
38
|
Thread.current[:formatador].indent do
|
39
|
-
data << collection.map
|
39
|
+
data << collection.map(&:inspect).join(",\n")
|
40
40
|
data << "\n"
|
41
41
|
end
|
42
42
|
data << Thread.current[:formatador].indentation
|
@@ -48,6 +48,6 @@ module Cistern::Formatter::Formatador
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def table(attributes = nil)
|
51
|
-
Formatador.display_table(
|
51
|
+
Formatador.display_table(map(&:attributes), attributes)
|
52
52
|
end
|
53
53
|
end
|
data/lib/cistern/hash.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Cistern::Hash
|
2
2
|
def self.slice(hash, *keys)
|
3
3
|
{}.tap do |sliced|
|
4
|
-
keys.each{ |k| sliced[k] = hash[k] if hash.key?(k) }
|
4
|
+
keys.each { |k| sliced[k] = hash[k] if hash.key?(k) }
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
@@ -18,9 +18,9 @@ class Cistern::Hash
|
|
18
18
|
def self.stringify_keys(object)
|
19
19
|
case object
|
20
20
|
when Hash
|
21
|
-
object.inject({}){|r,(k,v)| r.merge(k.to_s => stringify_keys(v))}
|
21
|
+
object.inject({}) { |r, (k, v)| r.merge(k.to_s => stringify_keys(v)) }
|
22
22
|
when Array
|
23
|
-
object.map{|v| stringify_keys(v) }
|
23
|
+
object.map { |v| stringify_keys(v) }
|
24
24
|
else
|
25
25
|
object
|
26
26
|
end
|
data/lib/cistern/mock.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cistern
|
2
2
|
class Mock
|
3
|
-
def self.not_implemented(method=
|
4
|
-
|
3
|
+
def self.not_implemented(method = '')
|
4
|
+
fail NotImplementedError, method ? "The call '#{method}' is not implemented" : ''
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.random_hex(length)
|
data/lib/cistern/model.rb
CHANGED
@@ -16,7 +16,7 @@ module Cistern::Model
|
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
19
|
-
def service_method(name=nil)
|
19
|
+
def service_method(name = nil)
|
20
20
|
@_service_method ||= name
|
21
21
|
end
|
22
22
|
end
|
@@ -27,7 +27,7 @@ module Cistern::Model
|
|
27
27
|
Cistern.formatter.call(self)
|
28
28
|
end
|
29
29
|
|
30
|
-
def initialize(attributes={})
|
30
|
+
def initialize(attributes = {})
|
31
31
|
merge_attributes(attributes)
|
32
32
|
end
|
33
33
|
|
@@ -37,7 +37,7 @@ module Cistern::Model
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def save
|
40
|
-
|
40
|
+
fail NotImplementedError
|
41
41
|
end
|
42
42
|
|
43
43
|
def reload
|
@@ -53,29 +53,29 @@ module Cistern::Model
|
|
53
53
|
def ==(comparison_object)
|
54
54
|
super ||
|
55
55
|
(comparison_object.is_a?(self.class) &&
|
56
|
-
comparison_object.identity ==
|
56
|
+
comparison_object.identity == identity &&
|
57
57
|
!comparison_object.new_record?)
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
alias_method :eql?, :==
|
61
61
|
|
62
62
|
def hash
|
63
|
-
if
|
64
|
-
[self.class,
|
63
|
+
if identity
|
64
|
+
[self.class, identity].join(':').hash
|
65
65
|
else
|
66
66
|
super
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
def wait_for(timeout =
|
70
|
+
def wait_for(timeout = service_class.timeout, interval = service_class.poll_interval, &block)
|
71
71
|
service_class.wait_for(timeout, interval) { reload && block.call(self) }
|
72
72
|
end
|
73
73
|
|
74
|
-
def wait_for!(timeout =
|
74
|
+
def wait_for!(timeout = service_class.timeout, interval = service_class.poll_interval, &block)
|
75
75
|
service_class.wait_for!(timeout, interval) { reload && block.call(self) }
|
76
76
|
end
|
77
77
|
|
78
78
|
def service_class
|
79
|
-
|
79
|
+
service ? service.class : Cistern
|
80
80
|
end
|
81
81
|
end
|
data/lib/cistern/request.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cistern::Request
|
2
2
|
def self.service_request(service, klass, name)
|
3
3
|
unless klass.name
|
4
|
-
|
4
|
+
fail ArgumentError, "can't turn anonymous class into a Cistern request"
|
5
5
|
end
|
6
6
|
|
7
7
|
service::Mock.module_eval <<-EOS, __FILE__, __LINE__
|
@@ -24,7 +24,7 @@ module Cistern::Request
|
|
24
24
|
end
|
25
25
|
|
26
26
|
module ClassMethods
|
27
|
-
def service_method(name=nil)
|
27
|
+
def service_method(name = nil)
|
28
28
|
@_service_method ||= name
|
29
29
|
end
|
30
30
|
end
|
data/lib/cistern/service.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Cistern::Service
|
2
2
|
def self.inherited(klass)
|
3
3
|
Cistern.deprecation(
|
4
|
-
|
5
|
-
caller[0]
|
4
|
+
'subclassing Cistern::Service is deprecated. Please use `include Cistern::Client`',
|
5
|
+
caller[0]
|
6
6
|
)
|
7
7
|
klass.send(:include, Cistern::Client)
|
8
8
|
end
|
data/lib/cistern/singular.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Cistern::Singular
|
2
|
-
|
3
2
|
def self.service_singular(service, klass, name)
|
4
3
|
service.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
|
5
4
|
def #{name}(attributes={})
|
@@ -28,12 +27,10 @@ module Cistern::Singular
|
|
28
27
|
def reload
|
29
28
|
new_attributes = fetch_attributes
|
30
29
|
|
31
|
-
if new_attributes
|
32
|
-
merge_attributes(new_attributes)
|
33
|
-
end
|
30
|
+
merge_attributes(new_attributes) if new_attributes
|
34
31
|
end
|
35
32
|
|
36
33
|
def fetch_attributes
|
37
|
-
|
34
|
+
fail NotImplementedError
|
38
35
|
end
|
39
36
|
end
|
data/lib/cistern/string.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
class Cistern::String
|
2
2
|
def self.camelize(string)
|
3
|
-
string.gsub(/[A-Z]+/) { |w| "_#{w.downcase}" }.gsub(/^_/,
|
3
|
+
string.gsub(/[A-Z]+/) { |w| "_#{w.downcase}" }.gsub(/^_/, '')
|
4
4
|
end
|
5
5
|
|
6
6
|
# File activesupport/lib/active_support/inflector/methods.rb, line 90
|
7
7
|
def self.underscore(camel_cased_word)
|
8
8
|
word = camel_cased_word.to_s.gsub('::', '/')
|
9
|
-
#word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
|
10
|
-
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
11
|
-
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
12
|
-
word.tr!(
|
9
|
+
# word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
|
10
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
11
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
12
|
+
word.tr!('-', '_')
|
13
13
|
word.downcase!
|
14
14
|
word
|
15
15
|
end
|
@@ -18,7 +18,7 @@ class Cistern::String
|
|
18
18
|
def self.demodulize(path)
|
19
19
|
path = path.to_s
|
20
20
|
if i = path.rindex('::')
|
21
|
-
path[(i+2)..-1]
|
21
|
+
path[(i + 2)..-1]
|
22
22
|
else
|
23
23
|
path
|
24
24
|
end
|