From 4df1819854658aa3d470b4cf7dbe9fdd68332e48 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Fri, 3 Nov 2017 16:14:30 +0100 Subject: [PATCH] refactoring Signed-off-by: Gwenhael Le Moine --- Gemfile.lock | 37 -------------------------- app.rb | 21 ++------------- config.ru | 9 ++----- config/options.rb | 6 ----- gems.locked | 34 +++++++++++++++++++++++ Gemfile => gems.rb | 2 -- options.rb | 6 +++++ public/app/js/templates/dashboard.html | 2 +- tasks/pry.rake | 8 +----- 9 files changed, 46 insertions(+), 79 deletions(-) delete mode 100644 Gemfile.lock delete mode 100644 config/options.rb create mode 100644 gems.locked rename Gemfile => gems.rb (71%) create mode 100644 options.rb diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 47dde8c1..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,37 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - coderay (1.1.1) - method_source (0.8.2) - pry (0.10.4) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - puma (3.6.0) - rack (1.6.4) - rack-protection (1.5.3) - rack - rack-rewrite (1.5.1) - rake (11.3.0) - sinatra (1.4.7) - rack (~> 1.5) - rack-protection (~> 1.4) - tilt (>= 1.3, < 3) - sinatra-param (1.4.0) - sinatra (~> 1.3) - slop (3.6.0) - tilt (2.0.5) - -PLATFORMS - ruby - -DEPENDENCIES - pry - puma - rack-rewrite - rake - sinatra - sinatra-param - -BUNDLED WITH - 1.13.6 diff --git a/app.rb b/app.rb index a5b7a065..5c99a3bf 100644 --- a/app.rb +++ b/app.rb @@ -4,12 +4,11 @@ require 'json' Bundler.require( :default, ENV[ 'RACK_ENV' ].to_sym ) +require_relative './options' require_relative './lib/ledger' # Sinatra app serving API class LedgerRbApp < Sinatra::Base - helpers Sinatra::Param - before do content_type :json, 'charset' => 'utf-8' end @@ -24,8 +23,6 @@ class LedgerRbApp < Sinatra::Base end get '/api/ledger/accounts/depth/:depth/?' do - param :depth, Integer, required: true - Ledger.accounts( params[ :depth ] ).to_json end @@ -34,20 +31,12 @@ class LedgerRbApp < Sinatra::Base end get '/api/ledger/register/?' do - param :period, String, default: nil - param :categories, String, required: true - { key: params[ :categories ], values: Ledger.register( params[ :period ], params[ :categories ] ) } .to_json end get '/api/ledger/balance/?' do - param :depth, Integer, default: false - param :period, String, default: nil - param :cleared, Boolean, default: false - param :categories, String, default: '' - Ledger.balance( params[ :cleared ], params[ :depth ], params[ :period ], @@ -60,17 +49,11 @@ class LedgerRbApp < Sinatra::Base end get '/api/ledger/budget/?' do - param :period, String, default: 'this month' - param :categories, String, required: true - Ledger.budget( params[ :period ], params[ :categories ] ).to_json end - - get '/api/ledger/graph_values/?' do - param :period, String, default: nil - param :categories, String, default: 'Expenses' + get '/api/ledger/graph_values/?' do Ledger.graph_values( params[:period], params[:categories].split(' ') ).to_json end diff --git a/config.ru b/config.ru index 604d9e61..e738e1a5 100644 --- a/config.ru +++ b/config.ru @@ -1,12 +1,7 @@ # encoding: utf-8 -require 'bundler' - -require_relative './config/options' require_relative './app' -use Rack::Rewrite do - rewrite %r{^/(.*(css|js|ttf|woff|html|png|jpg|jpeg|gif|ico)$)}, '/app/$1' +map "/" do + run LedgerRbApp end - -run LedgerRbApp diff --git a/config/options.rb b/config/options.rb deleted file mode 100644 index fe84e261..00000000 --- a/config/options.rb +++ /dev/null @@ -1,6 +0,0 @@ -# encoding: utf-8 - -ENV[ 'LEDGER_FILE' ] ||= '/home/owncloud-data/cycojesus/files/org-files/comptes.ledger' - -CURRENCY = '€' -SEPARATOR = ',' diff --git a/gems.locked b/gems.locked new file mode 100644 index 00000000..6e8cc63b --- /dev/null +++ b/gems.locked @@ -0,0 +1,34 @@ +GEM + remote: https://rubygems.org/ + specs: + coderay (1.1.2) + method_source (0.9.0) + mustermann (1.0.1) + pry (0.11.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + puma (3.10.0) + rack (2.0.3) + rack-protection (2.0.0) + rack + rack-rewrite (1.5.1) + rake (12.2.1) + sinatra (2.0.0) + mustermann (~> 1.0) + rack (~> 2.0) + rack-protection (= 2.0.0) + tilt (~> 2.0) + tilt (2.0.8) + +PLATFORMS + ruby + +DEPENDENCIES + pry + puma + rack-rewrite + rake + sinatra + +BUNDLED WITH + 1.14.6 diff --git a/Gemfile b/gems.rb similarity index 71% rename from Gemfile rename to gems.rb index 2a5e60a0..3887f1eb 100644 --- a/Gemfile +++ b/gems.rb @@ -2,9 +2,7 @@ source 'https://rubygems.org' -gem 'rack-rewrite' gem 'sinatra' -gem 'sinatra-param' gem 'puma' gem 'rake' gem 'pry' diff --git a/options.rb b/options.rb new file mode 100644 index 00000000..76ad01d9 --- /dev/null +++ b/options.rb @@ -0,0 +1,6 @@ +# encoding: utf-8 + +ENV[ 'LEDGER_FILE' ] ||= '/home/nextcloud/data/cycojesus/files/org-files/comptes.ledger' + +CURRENCY = '€' +SEPARATOR = ',' diff --git a/public/app/js/templates/dashboard.html b/public/app/js/templates/dashboard.html index b73daf89..a6726cf3 100644 --- a/public/app/js/templates/dashboard.html +++ b/public/app/js/templates/dashboard.html @@ -10,7 +10,7 @@ options="graphiques.monthly_values.options"> -

{{period | amDateFormat:'MMMM YYYY'}}

+

{{period | amDateFormat:'MMMM YYYY'}}

diff --git a/tasks/pry.rake b/tasks/pry.rake index 7ca725fb..1ea5dc37 100644 --- a/tasks/pry.rake +++ b/tasks/pry.rake @@ -2,13 +2,7 @@ ENV['RACK_ENV'] = 'development' task :load_config do - require 'rubygems' - require 'bundler' - - Bundler.require( :default, ENV['RACK_ENV'].to_sym ) # require tout les gems définis dans Gemfile - - require_relative '../lib/ledger' - require_relative '../config/options' + require_relative '../app' end desc 'Open pry with DB environment setup'