Sha256: b12021e011c51c715d81bb62c440e0b34f44de7d77d3c0b764aabd6fbe2f07de

Contents?: true

Size: 761 Bytes

Versions: 12

Compression:

Stored size: 761 Bytes

Contents

module Twitter
  class Factory

    # Instantiates a new action object
    #
    # @param attrs [Hash]
    # @raise [ArgumentError] Error raised when supplied argument is missing an :action key.
    # @return [Twitter::Action::Favorite, Twitter::Action::Follow, Twitter::Action::ListMemberAdded, Twitter::Action::Mention, Twitter::Action::Reply, Twitter::Action::Retweet]
    def self.fetch_or_new(method, klass, attrs={})
      return unless attrs
      type = attrs.delete(method.to_sym)
      if type
        const_name = type.gsub(/\/(.?)/){"::#{$1.upcase}"}.gsub(/(?:^|_)(.)/){$1.upcase}
        klass.const_get(const_name.to_sym).fetch_or_new(attrs)
      else
        raise ArgumentError, "argument must have :#{method} key"
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
twitter-4.8.1 lib/twitter/factory.rb
twitter-4.8.0 lib/twitter/factory.rb
twitter-4.7.0 lib/twitter/factory.rb
twitter-4.6.2 lib/twitter/factory.rb
twitter-4.6.1 lib/twitter/factory.rb
twitter-4.6.0 lib/twitter/factory.rb
twitter-4.5.0 lib/twitter/factory.rb
twitter-4.4.4 lib/twitter/factory.rb
twitter-4.4.3 lib/twitter/factory.rb
twitter-4.4.2 lib/twitter/factory.rb
twitter-4.4.1 lib/twitter/factory.rb
twitter-4.4.0 lib/twitter/factory.rb