Class: MTV::Base
- Inherits:
-
Object
- Object
- MTV::Base
- Defined in:
- lib/mtv/base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#attribute_for_inspect(attr_name) ⇒ Object
Copied from ActiveRecord::Base.
-
#initialize(values = {}) ⇒ Base
constructor
—————– Instance Methods —————–.
Constructor Details
#initialize(values = {}) ⇒ Base
Instance Methods
38 39 40 |
# File 'lib/mtv/base.rb', line 38 def initialize(values={}) values.each { |k, v| send "#{k}=", v } end |
Class Method Details
.request(path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mtv/base.rb', line 10 def request path url = URI.escape "#{base_url}/#{path}" response = nil seconds = Benchmark.realtime { response = open url } puts " \e[4;36;1mREQUEST (#{sprintf("%f", seconds)})\e[0m \e[0;1m#{url}\e[0m" if debug response.is_a?(String) ? response : response.read rescue OpenURI::HTTPError => e puts " \e[4;36;1mREQUEST (404)\e[0m \e[0;1m#{url}\e[0m" if debug nil end |
Instance Method Details
#attribute_for_inspect(attr_name) ⇒ Object
Copied from ActiveRecord::Base
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mtv/base.rb', line 43 def attribute_for_inspect(attr_name) value = send(attr_name) if value.is_a?(String) && value.length > 50 "#{value[0..50]}...".inspect elsif value.is_a?(Date) || value.is_a?(Time) %("#{value.to_s(:db)}") else value.inspect end end |