tsundere 0.1.5 → 0.2.0
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/tsundere.rb +10 -1
- data/lib/tsundere/class_methods.rb +12 -4
- data/lib/tsundere/imouto.rb +35 -7
- data/lib/tsundere/instance_methods.rb +7 -0
- data/spec/imouto_spec.rb +34 -2
- data/tsundere.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/tsundere.rb
CHANGED
@@ -9,4 +9,13 @@ module Tsundere
|
|
9
9
|
def self.included(base)
|
10
10
|
base.extend ClassMethods
|
11
11
|
end # self.included
|
12
|
-
end # Tsundere
|
12
|
+
end # Tsundere
|
13
|
+
|
14
|
+
if defined? Rails and defined? ActiveSupport
|
15
|
+
ActiveSupport.on_load(:action_controller) do
|
16
|
+
include Tsundere
|
17
|
+
end #
|
18
|
+
ActiveSupport.on_load(:active_record) do
|
19
|
+
include Tsundere
|
20
|
+
end #
|
21
|
+
end # if
|
@@ -2,11 +2,14 @@
|
|
2
2
|
|
3
3
|
module Tsundere
|
4
4
|
module ClassMethods
|
5
|
-
attr_reader :look_array, :look_table, :
|
5
|
+
attr_reader :look_array, :look_table, :fail_table
|
6
6
|
attr_accessor :permission_table, :rank_table
|
7
7
|
|
8
8
|
def attr_tsundere *attributes, opts
|
9
9
|
attr_looker *attributes, opts
|
10
|
+
if defined? Rails and self.respond_to? :helper_method
|
11
|
+
helper_method :tsundere_for
|
12
|
+
end # if
|
10
13
|
end # attr_tsundere
|
11
14
|
|
12
15
|
def attr_looker *attributes, opts
|
@@ -23,6 +26,7 @@ module Tsundere
|
|
23
26
|
def attr_modifier_thing *attributes, opts
|
24
27
|
@rank_table ||= {}
|
25
28
|
@permission_table ||= {}
|
29
|
+
@fail_table ||= {}
|
26
30
|
[:looker, :toucher].each do |thing|
|
27
31
|
@permission_table[thing] ||= {
|
28
32
|
:array => [] ,
|
@@ -31,18 +35,22 @@ module Tsundere
|
|
31
35
|
end # each thing
|
32
36
|
type = opts[:type]
|
33
37
|
perm = opts[:as]
|
38
|
+
fail = opts[:fail]
|
34
39
|
case perm.class.to_s
|
35
40
|
when 'Hash'
|
36
41
|
perm.each do |key, lvl|
|
37
42
|
@rank_table[key] = lvl
|
38
|
-
|
43
|
+
@fail_table[key] ||= fail
|
44
|
+
@fail_table[lvl] ||= fail
|
39
45
|
ind = permission_table[type][:array].binary_search_raw([lvl, attributes]) { |a1, a2| a1.first <=> a2.first }
|
40
|
-
permission_table[type][:array].insert(ind, [lvl, attributes]).sort! { |a1, a2| a1.first <=> a2.first }
|
46
|
+
permission_table[type][:array].insert(ind, [lvl, attributes]) # .sort! { |a1, a2| a1.first <=> a2.first }
|
41
47
|
end # each perm
|
42
48
|
when 'Fixnum', 'Integer', 'Float'
|
49
|
+
@fail_table[perm] ||= fail
|
43
50
|
ind = permission_table[type][:array].binary_search_raw([perm, attributes]) { |a1, a2| a1.first <=> a2.first }
|
44
|
-
permission_table[type][:array].insert(ind, [perm, attributes]).sort! { |a1, a2| a1.first <=> a2.first }
|
51
|
+
permission_table[type][:array].insert(ind, [perm, attributes]) # .sort! { |a1, a2| a1.first <=> a2.first }
|
45
52
|
when 'String', 'Symbol'
|
53
|
+
@fail_table[perm] ||= fail
|
46
54
|
attributes.each do |attr|
|
47
55
|
(permission_table[type][:table][perm] ||= []) << attr
|
48
56
|
end # each attr
|
data/lib/tsundere/imouto.rb
CHANGED
@@ -8,24 +8,52 @@ module Tsundere
|
|
8
8
|
end # initialize
|
9
9
|
|
10
10
|
def method_missing meth, *args, &block
|
11
|
+
conditions = []
|
12
|
+
conditions << lambda do
|
13
|
+
:[] == meth and @parent.dere_for? @level, process_args( *args )
|
14
|
+
end
|
15
|
+
conditions << lambda do
|
16
|
+
:[]= == meth and @parent.dere_for? @level, process_args( *args[0..-2] )
|
17
|
+
end
|
18
|
+
conditions << lambda do
|
19
|
+
@parent.dere_for? @level, meth
|
20
|
+
end
|
11
21
|
if @parent.respond_to? meth
|
12
|
-
if
|
13
|
-
|
14
|
-
|
22
|
+
if conditions.inject(false) { |mem, c| mem or c.call }
|
23
|
+
case meth
|
24
|
+
when :[]
|
25
|
+
@parent[*args, &block] unless block.nil?
|
26
|
+
@parent[*args] if block.nil?
|
27
|
+
when :[]=
|
28
|
+
tail = args.pop
|
29
|
+
|
30
|
+
@parent[*args] = tail
|
31
|
+
else
|
32
|
+
@parent.send(meth, *args, &block) unless block.nil?
|
33
|
+
@parent.send(meth, *args) if block.nil?
|
34
|
+
end # meth
|
15
35
|
else
|
16
|
-
return
|
17
|
-
end # if
|
36
|
+
return @parent.tsun_for @level
|
37
|
+
end # if conditions inject
|
18
38
|
else
|
19
39
|
super
|
20
|
-
end
|
40
|
+
end # if has method
|
21
41
|
end # method_missing
|
22
42
|
|
23
43
|
def respond_to? meth
|
24
44
|
if @parent.dere_for? @level, meth
|
25
45
|
@parent.respond_to? meth
|
46
|
+
elsif :[] == meth or :[]= == meth
|
47
|
+
@parent.respond_to? meth
|
26
48
|
else
|
27
49
|
false
|
28
50
|
end # if-dere
|
29
|
-
end #
|
51
|
+
end # respond_to
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def process_args *args
|
56
|
+
args.inject("") { |mem, arg| mem += arg.to_s }.to_sym
|
57
|
+
end # process_args
|
30
58
|
end # imouto
|
31
59
|
end # Tsundere
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# tsundere instance module
|
2
2
|
module Tsundere
|
3
|
+
|
3
4
|
def tsundere_for(duck)
|
4
5
|
level = p_retrieve_level_or_rank duck
|
5
6
|
Imouto.new self, level
|
@@ -22,7 +23,13 @@ module Tsundere
|
|
22
23
|
end # if-else
|
23
24
|
end # dere_for?
|
24
25
|
|
26
|
+
def tsun_for lvl
|
27
|
+
fail_msg = self.class.fail_table[lvl]
|
28
|
+
fail_msg ||= "Sorry #{lvl}, access is denied!"
|
29
|
+
end # tsun for
|
30
|
+
|
25
31
|
private
|
32
|
+
|
26
33
|
def p_retrieve_level_or_rank duck
|
27
34
|
case duck.class.to_s
|
28
35
|
when String.to_s, Fixnum.to_s, Float.to_s, Integer.to_s, Symbol.to_s
|
data/spec/imouto_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
class SchoolGirl
|
4
4
|
include Tsundere
|
5
|
-
attr_tsundere :show_up, :as => { :user => 1 }
|
6
|
-
attr_tsundere :brush_teeth, :as => { :oniichan => 2 }
|
5
|
+
attr_tsundere :show_up, :fail => "you are a faggot", :as => { :user => 1 }
|
6
|
+
attr_tsundere :brush_teeth, :fanservice, :as => { :oniichan => 2 }
|
7
7
|
|
8
8
|
def show_up
|
9
9
|
1
|
@@ -12,6 +12,15 @@ class SchoolGirl
|
|
12
12
|
def brush_teeth
|
13
13
|
2
|
14
14
|
end # brush
|
15
|
+
|
16
|
+
def []( k)
|
17
|
+
@internal[k]
|
18
|
+
end # getter
|
19
|
+
|
20
|
+
def []=( k, j)
|
21
|
+
@internal ||= {}
|
22
|
+
@internal[k] = j
|
23
|
+
end # setter
|
15
24
|
end # StereotypicalLoli
|
16
25
|
|
17
26
|
describe SchoolGirl do
|
@@ -31,4 +40,27 @@ describe SchoolGirl do
|
|
31
40
|
@tsukihi.tsundere_for(:oniichan).should respond_to :brush_teeth
|
32
41
|
@tsukihi.tsundere_for(:oniichan).should respond_to :show_up
|
33
42
|
end # it
|
43
|
+
[:user, :oniichan].each do |character|
|
44
|
+
[:[], :[]=].each do |fun|
|
45
|
+
it "should have the getter" do
|
46
|
+
@tsukihi.should respond_to fun
|
47
|
+
end # it
|
48
|
+
it "should have the getter" do
|
49
|
+
@tsukihi.tsundere_for(character).should respond_to fun
|
50
|
+
end # it
|
51
|
+
end # each fun
|
52
|
+
end # each character
|
53
|
+
describe "[]" do
|
54
|
+
before :each do
|
55
|
+
@tsukihi.tsundere_for(:oniichan)[:fanservice] = true
|
56
|
+
end # each
|
57
|
+
it "should only fanservice oniichan" do
|
58
|
+
@tsukihi[:fanservice].should eq true
|
59
|
+
@tsukihi.tsundere_for(:oniichan)[:fanservice].should eq true
|
60
|
+
end # it
|
61
|
+
it "should not work for regular user" do
|
62
|
+
@tsukihi.tsundere_for(:user)[:fanservice].should =~ /faggot/i
|
63
|
+
end # it
|
64
|
+
end # []
|
65
|
+
|
34
66
|
end # SchoolGirl
|
data/tsundere.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "tsundere"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Thomas Chen", "Trevor Umeda"]
|
12
|
-
s.date = "2012-12-
|
12
|
+
s.date = "2012-12-13"
|
13
13
|
s.description = "Any given object can implement the tsundere interface. Once implemented, a tsundere object will behave differently based upon who is calling it."
|
14
14
|
s.email = ["foxnewsnetwork@gmail.com", "FroggyP@gmail.com"]
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tsundere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: debugger
|
@@ -165,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
segments:
|
167
167
|
- 0
|
168
|
-
hash:
|
168
|
+
hash: 358892739405293387
|
169
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
170
|
none: false
|
171
171
|
requirements:
|