Module: HypertextClient
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/hypertext_client/hypertext_client.rb
Overview
Hypertext provides an HTTP client based on HTTParty, with a few assumptions baked in.
Defined Under Namespace
Modules: ClassMethods Classes: MissingArgumentError, NotFoundException
Constant Summary collapse
- VERSION =
'0.0.10'
Instance Method Summary collapse
-
#get_related(related) ⇒ Object
Get a related property.
-
#has_related?(related) ⇒ Boolean
A simple wrapper, we have a property if we have it’s URL.
-
#method_missing(name, *args) ⇒ Object
Make a GET request to provide a requested property, if we have a URL for that name.
-
#persisted? ⇒ Boolean
HypertextClient isn’t persisted, yet.
-
#to_model ⇒ Object
Simply returns self.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Make a GET request to provide a requested property, if we have a URL for that name.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hypertext_client/hypertext_client.rb', line 42 def method_missing(name, *args) if name =~ /^has_(\w+)_url\?$/ super(name, *args) elsif name =~ /^has_(\w+)\?$/ field = $1.to_sym super(name, *args) ? super(field, *args) : (field) elsif self.respond_to?((name.to_s + '_url').to_sym) self.(name) else super(name, *args) end end |
Instance Method Details
#get_related(related) ⇒ Object
Get a related property.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/hypertext_client/hypertext_client.rb', line 72 def () if .to_s =~ /[Aa]lias/ # patch over bug in ActiveSupport::Inflector klass = (self.class.name.split('::').first + '::' + 'Alias').constantize else klass = (self.class.name.split('::').first + '::' + .to_s.singularize.classify).constantize end result = klass.get(send (.to_s+'_url').to_sym) (class << self; self; end).instance_eval do define_method do result end end result end |
#has_related?(related) ⇒ Boolean
A simple wrapper, we have a property if we have it’s URL.
56 57 58 |
# File 'lib/hypertext_client/hypertext_client.rb', line 56 def () send "has_#{}_url?" end |
#persisted? ⇒ Boolean
HypertextClient isn’t persisted, yet.
67 68 69 |
# File 'lib/hypertext_client/hypertext_client.rb', line 67 def persisted? false end |
#to_model ⇒ Object
Simply returns self
62 63 64 |
# File 'lib/hypertext_client/hypertext_client.rb', line 62 def to_model self end |