Module: Hateoas::MediaType
- Defined in:
- lib/hateoas.rb
Defined Under Namespace
Classes: Request
Class Method Summary collapse
Instance Method Summary collapse
- #actions ⇒ Object
- #data ⇒ Object
- #initialize(uri) ⇒ Object
- #media_type ⇒ Object
- #relation_exists?(rel) ⇒ Boolean
- #transition(rel) ⇒ Object
Class Method Details
.included(including_class) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hateoas.rb', line 8 def self.included(including_class) including_class.class_eval do def self.media_type(type) @media_type = type end def self.serialization(type) end def self.element(*elements) end def self.attribute(*attributes) end def self.relation(*relations) end def self.action(*actions) @actions = actions end def self.actions @actions end end end |
Instance Method Details
#actions ⇒ Object
56 57 58 |
# File 'lib/hateoas.rb', line 56 def actions self.class.actions.select{|rel| relation_exists?(rel) } end |
#data ⇒ Object
54 |
# File 'lib/hateoas.rb', line 54 def data; @data; end |
#initialize(uri) ⇒ Object
60 61 62 |
# File 'lib/hateoas.rb', line 60 def initialize(uri) @data = Nokogiri::XML(Request.new(uri, @media_type).get) end |
#media_type ⇒ Object
53 |
# File 'lib/hateoas.rb', line 53 def media_type; @media_type; end |
#relation_exists?(rel) ⇒ Boolean
64 65 66 |
# File 'lib/hateoas.rb', line 64 def relation_exists?(rel) @data.xpath("//*[@rel='#{rel}']").first end |