Class: AffirmIt::Affirmation
- Inherits:
-
Object
- Object
- AffirmIt::Affirmation
- Includes:
- Esteem
- Defined in:
- lib/affirmit/affirmation.rb
Constant Summary collapse
- PASSTHROUGH_EXCEPTIONS =
These issues are not raised to the facilitator by #embrace. Recycled from Test::Unit.
[NoMemoryError, SignalException, Interrupt, SystemExit]
Constants included from Esteem
Instance Attribute Summary collapse
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
Attributes included from Esteem
Class Method Summary collapse
-
.group_hug ⇒ Object
Collects all the individual affirmations in this class into a big group hug.
Instance Method Summary collapse
- #add_bonus_point ⇒ Object
- #add_preference ⇒ Object
- #affirmation_count ⇒ Object
-
#build_up ⇒ Object
Affirmations may want to build themselves up before they are embraced by a facilitator.
- #embrace(facilitator) ⇒ Object
-
#initialize(method_name) ⇒ Affirmation
constructor
A new instance of Affirmation.
- #name ⇒ Object
- #praise(object, msg = '') ⇒ Object
-
#recycle ⇒ Object
After being embraced, whether their opinions are preferred by the facilitator or not, affirmations should take care of their environment and recycle any resources that they have consumed when building themselves up.
Methods included from Esteem
#defer_success, #maybe, #method_missing, #prefer_no_raise, #prefer_raise, #prefer_that
Methods included from Preferences
#a, #an, #between, #equals, #greater_than, #includes, #is, #isnt, #less_than, #matches, #responds_to, #same_as
Constructor Details
#initialize(method_name) ⇒ Affirmation
Returns a new instance of Affirmation.
15 16 17 18 19 20 21 22 23 |
# File 'lib/affirmit/affirmation.rb', line 15 def initialize(method_name) # Ruby syntax note: If we don't put the parentheses here, # it calls the super's initialize method with all the # parameters supplied to this method. However, # Esteem.initialize takes no parameters, so I have to # explicitly pass it no parameters. super() @method_name = method_name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AffirmIt::Esteem
Instance Attribute Details
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
13 14 15 |
# File 'lib/affirmit/affirmation.rb', line 13 def method_name @method_name end |
Class Method Details
.group_hug ⇒ Object
Collects all the individual affirmations in this class into a big group hug.
30 31 32 33 34 35 36 37 38 |
# File 'lib/affirmit/affirmation.rb', line 30 def group_hug group_hug = GroupHug.new(name) # name = class name public_instance_methods(true).sort.each do |method_name| if method_name =~ /^affirm[^A-Za-z0-9]/ group_hug << new(method_name) end end group_hug end |
Instance Method Details
#add_bonus_point ⇒ Object
70 71 72 |
# File 'lib/affirmit/affirmation.rb', line 70 def add_bonus_point @facilitator.add_bonus_point end |
#add_preference ⇒ Object
66 67 68 |
# File 'lib/affirmit/affirmation.rb', line 66 def add_preference @facilitator.add_preference end |
#affirmation_count ⇒ Object
58 59 60 |
# File 'lib/affirmit/affirmation.rb', line 58 def affirmation_count 1 end |
#build_up ⇒ Object
Affirmations may want to build themselves up before they are embraced by a facilitator. If so, they should inherit and more fully define the build_up method.
46 47 |
# File 'lib/affirmit/affirmation.rb', line 46 def build_up end |
#embrace(facilitator) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/affirmit/affirmation.rb', line 78 def embrace facilitator @facilitator = facilitator success = false facilitator.with_arms_around self do begin build_up __send__ @method_name success = true rescue DifferingOpinion => opinion facilitator.espouse_differing_opinion opinion rescue ElectiveDeferral => deferral facilitator.defer_success deferral rescue IntolerantPig => pig facilitator.expel pig rescue BehavioralChallenge => challenge facilitator.admit_challenge challenge rescue Exception => e raise e if PASSTHROUGH_EXCEPTIONS.include? e.class facilitator.raise_issue e ensure begin recycle facilitator.cherish_affirmation if success rescue DifferingOpinion => opinion facilitator.espouse_differing_opinion opinion rescue ElectiveDeferral => deferral facilitator.defer_success deferral rescue IntolerantPig => pig facilitator.expel pig rescue BehavioralChallenge => challenge facilitator.admit_challenge challenge rescue Exception => e raise e if PASSTHROUGH_EXCEPTIONS.include? e.class facilitator.raise_issue e end end end facilitator.add_affirmation @facilitator = nil end |
#name ⇒ Object
62 63 64 |
# File 'lib/affirmit/affirmation.rb', line 62 def name "#{self.class.name}.#{@method_name}" end |
#praise(object, msg = '') ⇒ Object
74 75 76 |
# File 'lib/affirmit/affirmation.rb', line 74 def praise object, msg = '' @facilitator.praise "What a wonderful #{object}! #{msg}" end |
#recycle ⇒ Object
After being embraced, whether their opinions are preferred by the facilitator or not, affirmations should take care of their environment and recycle any resources that they have consumed when building themselves up. In order to do so, they should inherit and define the recycle method.
55 56 |
# File 'lib/affirmit/affirmation.rb', line 55 def recycle end |