Module: TMDBParty::Attributes::ClassMethods

Defined in:
lib/tmdb_party/extras/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/extras/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 "    def \#{name}\n      read_or_load_attribute('\#{name}', \#{options[:type]}, \#{options[:lazy].inspect})\n    end\n  EVAL\nend\n"

#attributes(*names) ⇒ Object



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

def attributes(*names)
  options = names.last.is_a?(::Hash) ? names.pop : {}

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