Module: SubType::Expand

Defined in:
lib/subtype.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/subtype.rb', line 104

def self.included (klass)
  klass.instance_eval {
    helper do
      def __refresh
        self.data = self.respond_to?(:refresh) ? self.refresh : ''
      rescue
        self.data = 'ERROR'
      end
    end

    on :run do |s|
      s.type = s.type ? s.type : :short
      s.__refresh
    end

    on :mouse_over do |s|
      s.type = :long
      s.__refresh
    end

    on :mouse_out do |s|
      s.type = :short
      s.__refresh
    end

    alias __on__ on

    def on(meth, &blk)
      case meth
      when :run
        __on__(meth) {|s|
          s.type = s.type ? s.type : :short
          blk.call(s)
          s.__refresh
        }
      when :mouse_over
        __on__(meth) {|s|
          blk.call(s)
          s.type = :long
          s.__refresh
        }
      when :mouse_out
        __on__(meth) {|s|
          blk.call(s)
          s.type = :short
          s.__refresh
        }
      else
        __on__(meth) {|*args|
          blk.call(*args)
          args.last.__refresh
        }
      end
    end
  }
end