Module: Tsundere::ClassMethods

Defined in:
lib/tsundere/class_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fail_tableObject (readonly)

Returns the value of attribute fail_table.



5
6
7
# File 'lib/tsundere/class_methods.rb', line 5

def fail_table
  @fail_table
end

#look_arrayObject (readonly)

Returns the value of attribute look_array.



5
6
7
# File 'lib/tsundere/class_methods.rb', line 5

def look_array
  @look_array
end

#look_tableObject (readonly)

Returns the value of attribute look_table.



5
6
7
# File 'lib/tsundere/class_methods.rb', line 5

def look_table
  @look_table
end

#permission_tableObject

Returns the value of attribute permission_table.



6
7
8
# File 'lib/tsundere/class_methods.rb', line 6

def permission_table
  @permission_table
end

#rank_tableObject

Returns the value of attribute rank_table.



6
7
8
# File 'lib/tsundere/class_methods.rb', line 6

def rank_table
  @rank_table
end

Instance Method Details

#attr_looker(*attributes, opts) ⇒ Object

attr_tsundere



15
16
17
# File 'lib/tsundere/class_methods.rb', line 15

def attr_looker *attributes, opts
	attr_modifier_thing *attributes, opts.merge( :type => :looker )
end

#attr_modifier_thing(*attributes, opts) ⇒ Object

Yes, I realize this function looks like crap, but it’s late, I’m tired and this project is due really soon and I need sleep before I die. I’ll refactor this later. I swear.



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
58
# File 'lib/tsundere/class_methods.rb', line 26

def attr_modifier_thing *attributes, opts
	@rank_table ||= {}
	@permission_table ||= {}
	@fail_table ||= {}
	[:looker, :toucher].each do |thing|
		@permission_table[thing] ||= {
			:array => [] ,
			:table => {}
		}  # looker
	end  # each thing
	type = opts[:type]
	perm = opts[:as]
	fail = opts[:fail]
	case perm.class.to_s
	when 'Hash'
		perm.each do |key, lvl|
			@rank_table[key] = lvl
			@fail_table[key] ||= fail
			@fail_table[lvl] ||= fail 
			ind = permission_table[type][:array].binary_search_raw([lvl, attributes]) { |a1, a2| a1.first <=> a2.first } 
			permission_table[type][:array].insert(ind, [lvl, attributes]) # .sort! { |a1, a2| a1.first <=> a2.first } 
		end # each perm
	when 'Fixnum', 'Integer', 'Float'
		@fail_table[perm] ||= fail 
		ind = permission_table[type][:array].binary_search_raw([perm, attributes]) { |a1, a2| a1.first <=> a2.first } 
		permission_table[type][:array].insert(ind, [perm, attributes]) # .sort! { |a1, a2| a1.first <=> a2.first } 
	when 'String', 'Symbol'
		@fail_table[perm] ||= fail 
		attributes.each do |attr|
			(permission_table[type][:table][perm] ||= []) << attr
		end # each attr
	end # perm class
end

#attr_toucher(*attributes, opts) ⇒ Object

attr_looker



19
20
21
# File 'lib/tsundere/class_methods.rb', line 19

def attr_toucher *attributes, opts
	attr_modifier_thing *attributes, opts.merge( :type => :toucher )
end

#attr_tsundere(*attributes, opts) ⇒ Object



8
9
10
11
12
13
# File 'lib/tsundere/class_methods.rb', line 8

def attr_tsundere *attributes, opts
	attr_looker *attributes, opts
	if defined? Rails and self.respond_to? :helper_method
		helper_method :tsundere_for
	end # if
end