scintillation 0.1.0 → 0.1.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.
- data/VERSION +1 -1
- data/lib/scintillation.rb +42 -0
- data/scintillation.gemspec +2 -2
- data/spec/scintillation_spec.rb +45 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/scintillation.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Soccer022483
|
2
|
+
module Scintillation
|
3
|
+
class Messages
|
4
|
+
def initialize
|
5
|
+
@messages = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def method_missing(name, *args)
|
9
|
+
if /^(([a-z]+)_)?(message(s)?)(_for_([a -z]+))?$/.match(name.to_s)
|
10
|
+
options = {:tone => $2, :scope => $6}
|
11
|
+
($3 == 'message') ? send(:add, args.first, options) : send(:get, options)
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def add(body, options = {})
|
20
|
+
@messages << Message.new(body, options[:tone], options[:scope])
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(options = {})
|
24
|
+
msgs = []
|
25
|
+
@messages.delete_if do |m|
|
26
|
+
msgs << m if {:tone => m.tone, :scope => m.scope} == options
|
27
|
+
end
|
28
|
+
msgs
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Message
|
33
|
+
attr_reader :to_s, :tone, :scope
|
34
|
+
|
35
|
+
def initialize(body, tone = nil, scope = nil)
|
36
|
+
@to_s = body.to_s
|
37
|
+
@tone = tone.to_s unless tone !~ /\S/
|
38
|
+
@scope = scope.to_s unless scope !~ /\S/
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/scintillation.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{scintillation}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Austin Schneider"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-14}
|
13
13
|
s.description = %q{A flash messages replacement}
|
14
14
|
s.email = %q{soccer022483@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/scintillation_spec.rb
CHANGED
@@ -1,7 +1,49 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
SampleData = Struct.new(:setter_method, :getter_method, :tone, :scope) do
|
4
|
+
def body
|
5
|
+
setter_method
|
6
6
|
end
|
7
7
|
end
|
8
|
+
|
9
|
+
describe "Scintillation" do
|
10
|
+
it "messages" do
|
11
|
+
msgs_obj = Soccer022483::Scintillation::Messages.new
|
12
|
+
msgs_obj.instance_variable_get(:@messages).should be_empty
|
13
|
+
|
14
|
+
samples = []
|
15
|
+
samples << SampleData.new('message', 'messages', nil, nil)
|
16
|
+
samples << SampleData.new('positive_message', 'positive_messages', 'positive', nil)
|
17
|
+
samples << SampleData.new('message_for_login', 'messages_for_login', nil, 'login')
|
18
|
+
samples << SampleData.new('negative_message_for_user', 'negative_messages_for_user', 'negative', 'user')
|
19
|
+
|
20
|
+
samples.each { |s| msgs_obj.send(s.setter_method, s.body) }
|
21
|
+
|
22
|
+
size = 4
|
23
|
+
|
24
|
+
samples.each do |s|
|
25
|
+
msgs_obj.instance_variable_get(:@messages).size.should == size
|
26
|
+
msgs = msgs_obj.send(s.getter_method)
|
27
|
+
msgs.size.should == 1
|
28
|
+
msgs.map { |m| [m.to_s, m.tone, m.scope] }.should == [[s.body, s.tone, s.scope]]
|
29
|
+
size -= 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "message" do
|
34
|
+
m = Soccer022483::Scintillation::Message.new("message")
|
35
|
+
[m.to_s, m.tone, m.scope].should == ['message', nil, nil]
|
36
|
+
|
37
|
+
m = Soccer022483::Scintillation::Message.new("message", nil, nil)
|
38
|
+
[m.to_s, m.tone, m.scope].should == ['message', nil, nil]
|
39
|
+
|
40
|
+
m = Soccer022483::Scintillation::Message.new("message", '', '')
|
41
|
+
[m.to_s, m.tone, m.scope].should == ['message', nil, nil]
|
42
|
+
|
43
|
+
m = Soccer022483::Scintillation::Message.new("message", ' ', ' ')
|
44
|
+
[m.to_s, m.tone, m.scope].should == ['message', nil, nil]
|
45
|
+
|
46
|
+
m = Soccer022483::Scintillation::Message.new("message", 'positive', 'login')
|
47
|
+
[m.to_s, m.tone, m.scope].should == ['message', 'positive', 'login']
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scintillation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Austin Schneider
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-14 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|