Module: TMDBParty::Attributes::ClassMethods

Defined in:
lib/tmdb_party/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, options) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
31
# File 'lib/tmdb_party/attributes.rb', line 22

def attribute(name, options)
  options = {:type => 'nil', :lazy => false}.merge(options)
  raise ArgumentError, "Name can't be empty" if name.blank?
  
  class_eval <<-EVAL
    def #{name}
      read_or_load_attribute('#{name}', #{options[:type]}, #{options[:lazy].inspect})
    end
  EVAL
end

#attributes(*names) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/tmdb_party/attributes.rb', line 14

def attributes(*names)
  options = names.extract_options!

  names.each do |name|
    attribute name, options unless name.blank?
  end
end