Module: TMDBParty::Attributes::ClassMethods

Defined in:
lib/tmdb_party/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, options) ⇒ Object



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

def attribute(name, options)
  options.replace({:type => 'nil', :lazy=>false}.merge(options))
  raise "Name can't be empty" if name.blank?
  lazy_load = "self.#{options[:lazy]} unless self.loaded?" if options[:lazy]
  class_eval <<-EOS
  def #{name}
    #{lazy_load}
    @#{name} ||= decode_raw_attribute(@attributes['#{name}'], #{options[:type]}) if @attributes
  end
  EOS
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