1
0
Fork 0

Cleaning up

This commit is contained in:
Gregory Eremin 2012-10-17 18:05:40 +04:00
parent 7c42a90a6c
commit 5c519506c0
5 changed files with 26 additions and 43 deletions

View File

@ -14,24 +14,11 @@ module MusicBrainz
data = params[:binding].parse(xml)
if params[:create_model]
result_model = params[:create_model].new
data.each do |field, value|
result_model.send("#{field}=".to_sym, value)
end
result_model
params[:create_model].new(data)
elsif params[:create_models]
result_models = []
data.each do |item|
result_model = params[:create_models].new
item.each do |field, value|
result_model.send("#{field}=".to_sym, value)
end
result_models << result_model
end
if params[:sort]
result_models.sort!{ |a, b| a.send(params[:sort]) <=> b.send(params[:sort]) }
end
result_models
models = data.map{ |item| params[:create_models].new(item) }
models.sort!{ |a, b| a.send(params[:sort]) <=> b.send(params[:sort]) } if params[:sort]
models
else
data
end

View File

@ -1,22 +1,6 @@
module MusicBrainz
def query_interval
MusicBrainz.config.query_interval
end
def query_interval=(value)
MusicBrainz.config.query_interval = value
end
def cache_path
MusicBrainz.config.cache_path
end
def cache_path=(value)
MusicBrainz.config.cache_path = value
end
module Tools
module Proxy
module Deprecated
module ProxyConfig
def query_interval
MusicBrainz.config.query_interval
end
@ -24,11 +8,9 @@ module MusicBrainz
def query_interval=(value)
MusicBrainz.config.query_interval = value
end
extend self
end
module Cache
module CacheConfig
def cache_path
MusicBrainz.config.cache_path
end
@ -36,10 +18,19 @@ module MusicBrainz
def cache_path=(value)
MusicBrainz.config.cache_path = value
end
extend self
end
end
extend self
module Tools
module Proxy
extend Deprecated::ProxyConfig
end
module Cache
extend Deprecated::CacheConfig
end
end
extend Deprecated::ProxyConfig
extend Deprecated::CacheConfig
end

View File

@ -18,6 +18,12 @@ module MusicBrainz
end
module InstanceMethods
def initialize(params = {})
params.each do |field, value|
self.send :"#{field}=", value
end
end
def validate_type(val, type)
if type == Integer
val.to_i

View File

@ -17,5 +17,4 @@ Gem::Specification.new do |gem|
gem.add_dependency("faraday")
gem.add_dependency("nokogiri")
gem.add_development_dependency("rspec")
gem.add_development_dependency("awesome_print")
end

View File

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# encoding: utf-8
require "ostruct"
require "spec_helper"