Class: Badgeable::Config
- Inherits:
-
Object
- Object
- Badgeable::Config
- Defined in:
- lib/badgeable/config.rb
Class Attribute Summary (collapse)
-
+ (Object) badge_definitions
Returns the value of attribute badge_definitions.
Instance Attribute Summary (collapse)
-
- (Object) conditions_array
readonly
Returns the value of attribute conditions_array.
-
- (Object) klass
readonly
Returns the value of attribute klass.
-
- (Object) subject_proc
readonly
Returns the value of attribute subject_proc.
-
- (Object) threshold
readonly
Returns the value of attribute threshold.
Instance Method Summary (collapse)
- - (Object) conditions(&block)
- - (Object) count(n = 1, &block)
- - (Object) description(*args)
- - (Object) icon(*args)
-
- (Config) initialize
constructor
A new instance of Config.
- - (Object) subject(sym = nil, &block)
- - (Object) thing(klass)
Constructor Details
- (Config) initialize
A new instance of Config
10 11 12 13 |
# File 'lib/badgeable/config.rb', line 10 def initialize @conditions_array = [Proc.new {true}] subject :user end |
Class Attribute Details
+ (Object) badge_definitions
Returns the value of attribute badge_definitions
5 6 7 |
# File 'lib/badgeable/config.rb', line 5 def badge_definitions @badge_definitions end |
Instance Attribute Details
- (Object) conditions_array (readonly)
Returns the value of attribute conditions_array
8 9 10 |
# File 'lib/badgeable/config.rb', line 8 def conditions_array @conditions_array end |
- (Object) klass (readonly)
Returns the value of attribute klass
8 9 10 |
# File 'lib/badgeable/config.rb', line 8 def klass @klass end |
- (Object) subject_proc (readonly)
Returns the value of attribute subject_proc
8 9 10 |
# File 'lib/badgeable/config.rb', line 8 def subject_proc @subject_proc end |
- (Object) threshold (readonly)
Returns the value of attribute threshold
8 9 10 |
# File 'lib/badgeable/config.rb', line 8 def threshold @threshold end |
Instance Method Details
- (Object) conditions(&block)
51 52 53 54 55 |
# File 'lib/badgeable/config.rb', line 51 def conditions(&block) @conditions_array << Proc.new {|instance| block.call(instance) } end |
- (Object) count(n = 1, &block)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/badgeable/config.rb', line 32 def count(n = 1, &block) if block_given? count_proc = Proc.new { |instance| block.call(instance) } else count_proc = Proc.new { |instance| instance.instance_eval %Q{ #{klass}.where(:#{@subject_name}_id => #{@subject_name}.id).count >= #{n} } } end @conditions_array << count_proc end |
- (Object) description(*args)
66 67 68 69 70 71 72 73 |
# File 'lib/badgeable/config.rb', line 66 def description(*args) raise ArgumentError unless args.length <= 1 if args.length == 1 @description = args[0] else @description end end |
- (Object) icon(*args)
57 58 59 60 61 62 63 64 |
# File 'lib/badgeable/config.rb', line 57 def icon(*args) raise ArgumentError unless args.length <= 1 if args.length == 1 @icon = args[0] else @icon end end |
- (Object) subject(sym = nil, &block)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/badgeable/config.rb', line 15 def subject(sym = nil, &block) @subject_name = sym if block_given? @subject_proc = Proc.new {|instance| block.call(instance) } else @subject_proc = Proc.new { |instance| if klass.to_s.underscore.to_sym == @subject_name instance else instance.send(sym) end } end end |
- (Object) thing(klass)
47 48 49 |
# File 'lib/badgeable/config.rb', line 47 def thing(klass) @klass = klass end |