Module: AppStore::Helper::Plist

Included in:
Base
Defined in:
lib/app_store/helpers/plist.rb

Instance Method Summary collapse

Instance Method Details

#plist(params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/app_store/helpers/plist.rb', line 4

def plist(params = {})
  mapping = params[:mapping].collect do |plist_key, attr_name|
    # First, make attribute readable outside the instance
    class_eval "attr_reader :#{attr_name}"
    
    # Then, build the content of init_from_plist function
    "@#{attr_name} = plist['#{plist_key}']"
  end rescue []
  
  class_eval "    protected\n    def init_from_plist(plist)\n      \#{\"raise AppStore::ParseError unless plist['type'] == '\#{params[:accepted_type]}'\" if params[:accepted_type]}\n      super\n      \#{mapping.join(\"\\n\")}\n    end\n  EOV\nend\n", __FILE__, __LINE__