Skip to content

Commit

Permalink
many class method for dynamically defining association methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremytregunna committed Feb 13, 2012
1 parent bacceed commit 2226eb6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/trello/basic_data.rb
Expand Up @@ -37,6 +37,19 @@ def self.register_attributes(*names)
end
end

def self.many(name, opts = {})
class_eval do
define_method(:"#{name}") do |*args|
options = opts.dup
resource = options.delete(:in) || self.class.to_s.split("::").last.downcase.pluralize
klass = options.delete(:via) || Trello.const_get(name.to_s.singularize.camelize)
params = options.merge(args[0] || {})
resources = Client.get("/#{resource}/#{id}/#{name}", options).json_into(klass)
MultiAssociation.new(self, resources).proxy
end
end
end

register_attributes :id, :readonly => [ :id ]

def initialize(fields = {})
Expand Down

0 comments on commit 2226eb6

Please sign in to comment.