module TinyClient::NestedSupport::ClassMethods

Add support for the {#nested} class methods as well as default actions.

Public Instance Methods

nested(*clazz) click to toggle source

Set nested resources. Nested resource creation and getters method will be created. If the resource class is called Post, then `add_post` and `posts` methods will be created. @param [Resource] clazz the nested resource class.

# File lib/tiny_client/nested_support.rb, line 74
def nested(*clazz)
  @nested ||= nested_actions(clazz) && clazz
end

Private Instance Methods

nested_actions(nested) click to toggle source
# File lib/tiny_client/nested_support.rb, line 80
      def nested_actions(nested)
        nested.each do |clazz|
          plural_name = ActiveSupport::Inflector.pluralize(clazz.low_name)
          class_eval <<-RUBY
            def #{plural_name}(params = {}); nested_index(#{clazz}, params) end
            def #{clazz.low_name}(id, params = {}); nested_show(#{clazz}, id, params) end
            def add_#{clazz.low_name}(#{clazz.low_name}); nested_create(#{clazz.low_name}) end
            def update_#{clazz.low_name}(#{clazz.low_name}); nested_update(#{clazz.low_name}) end
            def remove_#{clazz.low_name}(#{clazz.low_name}); nested_delete(#{clazz.low_name}) end
            def #{plural_name}_all(params = {}); nested_all(#{clazz}, params) end
          RUBY
        end
      end