From 338ca286a4528aaf3a45eeddc9deb26bff49e566 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 27 Jul 2014 17:20:08 +0800 Subject: [PATCH] Extract ActiveYaml base class We use universal config root path. --- app/models/active_yaml_base.rb | 3 +++ app/models/currency.rb | 4 +--- app/models/deposit_channel.rb | 4 +--- app/models/market.rb | 4 +--- app/models/withdraw_channel.rb | 4 +--- 5 files changed, 7 insertions(+), 12 deletions(-) create mode 100644 app/models/active_yaml_base.rb diff --git a/app/models/active_yaml_base.rb b/app/models/active_yaml_base.rb new file mode 100644 index 0000000000..edc1d04bb8 --- /dev/null +++ b/app/models/active_yaml_base.rb @@ -0,0 +1,3 @@ +class ActiveYamlBase < ActiveYaml::Base + set_root_path "#{Rails.root}/config" +end diff --git a/app/models/currency.rb b/app/models/currency.rb index fb873bc2a7..9c5b1da3a7 100644 --- a/app/models/currency.rb +++ b/app/models/currency.rb @@ -1,9 +1,7 @@ -class Currency < ActiveYaml::Base +class Currency < ActiveYamlBase include International include ActiveHash::Associations - set_root_path "#{Rails.root}/config" - def self.hash_codes @codes ||= Hash[*all.map do |x| [x.code, x.id] end.flatten].symbolize_keys end diff --git a/app/models/deposit_channel.rb b/app/models/deposit_channel.rb index 31dcb4601e..6de1094589 100644 --- a/app/models/deposit_channel.rb +++ b/app/models/deposit_channel.rb @@ -1,6 +1,4 @@ -class DepositChannel < ActiveYaml::Base - set_root_path "#{Rails.root}/config" - +class DepositChannel < ActiveYamlBase include Channelable include HashCurrencible include International diff --git a/app/models/market.rb b/app/models/market.rb index fb73c3116d..efb4b63473 100644 --- a/app/models/market.rb +++ b/app/models/market.rb @@ -8,11 +8,9 @@ # _cny_, buyers buy in _btc_ with _cny_. _btc_ is the `target`, while _cny_ # is the `price`. -class Market < ActiveYaml::Base +class Market < ActiveYamlBase include Enumerizeable - set_root_path "#{Rails.root}/config" - attr :name, :target_unit, :price_unit # TODO: our market id is the opposite of conventional market name. diff --git a/app/models/withdraw_channel.rb b/app/models/withdraw_channel.rb index 2bbe3c22fa..f989a64859 100644 --- a/app/models/withdraw_channel.rb +++ b/app/models/withdraw_channel.rb @@ -1,6 +1,4 @@ -class WithdrawChannel < ActiveYaml::Base - set_root_path "#{Rails.root}/config" - +class WithdrawChannel < ActiveYamlBase include Channelable include HashCurrencible include International