From 4875a770acd0e2bb82498d88453e2a15bd3096ed Mon Sep 17 00:00:00 2001 From: fauno Date: Sat, 6 Apr 2019 17:41:44 -0300 Subject: [PATCH] =?UTF-8?q?documentaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 1 - .gitignore | 3 +++ Dockerfile | 6 +++-- Gemfile | 1 + Gemfile.lock | 2 ++ Makefile | 7 +++++- app/controllers/consensos_controller.rb | 27 +++++++++++++++++++--- app/controllers/piratas_controller.rb | 6 +++++ app/controllers/posiciones_controller.rb | 12 ++++++++++ app/models/consenso.rb | 3 ++- app/views/piratas/create.json.jbuilder | 2 +- bin/yard | 29 ++++++++++++++++++++++++ bin/yardoc | 29 ++++++++++++++++++++++++ bin/yri | 29 ++++++++++++++++++++++++ config/database.yml | 2 +- entrypoint.sh | 11 +++++++++ monit.conf | 4 ++++ 17 files changed, 164 insertions(+), 10 deletions(-) create mode 100755 bin/yard create mode 100755 bin/yardoc create mode 100755 bin/yri diff --git a/.dockerignore b/.dockerignore index b82bb49..ed9f8bf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,7 +3,6 @@ node_modules/ tmp/ log/ public/ -docs/ bin/ db/ lib/ diff --git a/.gitignore b/.gitignore index 1dfe532..a1aa2a9 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ /config/master.key # Siempre da conflictos /db/schema.rb +/public/docs/ +/.yardoc/ +/docs/ diff --git a/Dockerfile b/Dockerfile index a1ba04f..bbd7ba0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ RUN git archive -o ../web.tar.gz HEAD FROM lunar/monit:3.9 RUN apk add --no-cache libxslt libxml2 tzdata ruby ruby-bundler ruby-json ruby-bigdecimal ruby-rake RUN apk add --no-cache sqlite sqlite-libs -RUN addgroup -g 82 -S www-data +RUN apk add --no-cache darkhttpd COPY ./entrypoint.sh /usr/bin/entrypoint RUN chmod 755 /usr/bin/entrypoint # Agregar el usuario @@ -46,9 +46,11 @@ RUN tar xf /tmp/web.tar.gz && rm /tmp/web.tar.gz # Traer las gemas COPY --from=build --chown=app:www-data /home/app/web/vendor ./vendor COPY --from=build --chown=app:www-data /home/app/web/.bundle ./.bundle +COPY --chown=app:www-data ./docs ./public/docs USER root RUN install -m 640 -o root -g root ./monit.conf /etc/monit.d/puma.conf RUN monit -t -VOLUME "/srv/http/public/system" +VOLUME "/srv/http/data" EXPOSE 3000 +EXPOSE 8080 diff --git a/Gemfile b/Gemfile index d5b1ec7..635e963 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,7 @@ group :development do gem 'rubocop' gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' + gem 'yard' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index b719226..9f56cf1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -160,6 +160,7 @@ GEM websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) + yard (0.9.19) PLATFORMS ruby @@ -179,6 +180,7 @@ DEPENDENCIES spring spring-watcher-listen (~> 2.0.0) sqlite3 + yard RUBY VERSION ruby 2.5.3p105 diff --git a/Makefile b/Makefile index 9eb5ac6..9a1c74c 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,11 @@ c ?= $(shell date +%F | tr "-" ".") r ?= $(shell git rev-list --count HEAD) name = miniloom/$(d):$(c).$(r) +doc: + ./bin/yardoc --output-dir=./docs/ \ + app/controllers/*.rb \ + app/models/*.rb + clean: rm -f log/*.log rm -rf tmp/cache/assets @@ -22,4 +27,4 @@ push: docker push registry.forja.lainventoria.com.ar/$(name) docker push registry.forja.lainventoria.com.ar/miniloom/$(d):latest -all: clean build tag push +all: clean doc build tag push diff --git a/app/controllers/consensos_controller.rb b/app/controllers/consensos_controller.rb index 2cb98a0..c0c3f2a 100644 --- a/app/controllers/consensos_controller.rb +++ b/app/controllers/consensos_controller.rb @@ -1,15 +1,29 @@ # frozen_string_literal: true -# Consensos +# API para Consensos, necesita autenticar una pirata vía HTTP Basic Auth +# +# @see PiratasController#create class ConsensosController < ApplicationController + # Para cualquier acción necesitamos autenticación before_action :authenticate! + # GET /consensos + # # Podemos ver todos los consensos + # + # @return [Array] [ consensos ] def index @consensos = Consenso.all.order(:created_at, :desc) end - # Podemos ver uno solo + # GET /consensos/:id + # + # Podemos ver uno solo sabiendo su ID + # + # @param id [Integer] El ID del consenso + # @return [Hash] { id: @int, created_at: @date, + # titulo: @string, texto: @string, + # posiciones: [] } def show @consenso = Consenso.find(params[:id]) return if @consenso @@ -17,7 +31,14 @@ class ConsensosController < ApplicationController render json: {}, status: :not_found end - # Podemos crear uno + # POST /consensos + # + # Podemos crear uno, enviando un hash con todas las propiedades + # + # @param consenso [Hash] { consenso: { titulo: @string, texto: @string } } + # @return [Hash] { id: @int, created_at: @date, + # titulo: @string, texto: @string, + # posiciones: [] } def create @consenso = current_pirata.consensos .new(params.require(:consenso).permit(:titulo, :texto)) diff --git a/app/controllers/piratas_controller.rb b/app/controllers/piratas_controller.rb index f472f72..ee699be 100644 --- a/app/controllers/piratas_controller.rb +++ b/app/controllers/piratas_controller.rb @@ -2,7 +2,13 @@ # Las piratas son las que activan el Miniloom class PiratasController < ApplicationController + # POST /piratas + # # Registra una cuenta + # + # @param pirata [Hash] { pirata: { password: @string, email: @string, + # nick: @string } } + # @return [Hash] { id: @int, nick: @string, email: @string } def create @pirata = Pirata.new(params .require(:pirata) diff --git a/app/controllers/posiciones_controller.rb b/app/controllers/posiciones_controller.rb index 4fb0d2d..900c134 100644 --- a/app/controllers/posiciones_controller.rb +++ b/app/controllers/posiciones_controller.rb @@ -1,9 +1,21 @@ # frozen_string_literal: true +# API para posiciones +# # Las posiciones solo se pueden agregar a su consenso +# +# @see PiratasController#create class PosicionesController < ApplicationController + # Necesitamos autenticarnos before_action :authenticate! + # POST /consensos/:consenso_id/posiciones + # + # Crea una posición dentro de un consenso + # + # @param :consenso_id [Integer] El ID del consenso + # @param :posicion [Hash] { posicion: { estado: @string, comentario: @string } } + # @return [Hash] { id: @int, estado: @string, comentario: @string } def create @consenso = Consenso.find(params[:consenso_id]) @posicion = @consenso.try(:posiciones).try(:build, posicion_params) diff --git a/app/models/consenso.rb b/app/models/consenso.rb index d325372..fe1a255 100644 --- a/app/models/consenso.rb +++ b/app/models/consenso.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -# El consenso agrupa posiciones y textos +# Los consensos son textos sobre los que las piratas establecen +# posiciones class Consenso < ApplicationRecord # Es escrito por una pirata belongs_to :pirata diff --git a/app/views/piratas/create.json.jbuilder b/app/views/piratas/create.json.jbuilder index 6c37603..09b3b99 100644 --- a/app/views/piratas/create.json.jbuilder +++ b/app/views/piratas/create.json.jbuilder @@ -1,3 +1,3 @@ # frozen_string_literal: true -json.call(@pirata, :nick, :email) +json.call(@pirata, :id, :nick, :email) diff --git a/bin/yard b/bin/yard new file mode 100755 index 0000000..19803d4 --- /dev/null +++ b/bin/yard @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'yard' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path('bundle', __dir__) + +if File.file?(bundle_binstub) + if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300)) + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('yard', 'yard') diff --git a/bin/yardoc b/bin/yardoc new file mode 100755 index 0000000..979e925 --- /dev/null +++ b/bin/yardoc @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'yardoc' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path('bundle', __dir__) + +if File.file?(bundle_binstub) + if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300)) + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('yard', 'yardoc') diff --git a/bin/yri b/bin/yri new file mode 100755 index 0000000..bd7e920 --- /dev/null +++ b/bin/yri @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'yri' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path('bundle', __dir__) + +if File.file?(bundle_binstub) + if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300)) + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('yard', 'yri') diff --git a/config/database.yml b/config/database.yml index 0d02f24..f7a3238 100644 --- a/config/database.yml +++ b/config/database.yml @@ -22,4 +22,4 @@ test: production: <<: *default - database: db/production.sqlite3 + database: data/production.sqlite3 diff --git a/entrypoint.sh b/entrypoint.sh index c36ce8d..89bb142 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,4 +10,15 @@ case $1 in bundle exec puma -d config.ru exit $? ;; + darkhttpd) + darkhttpd /srv/http/public \ + --no-server-id \ + --pidfile /tmp/darkhttpd.pid \ + --uid darkhttpd \ + --gid www-data \ + --no-listing \ + --daemon \ + --port 8080 + exit $? + ;; esac diff --git a/monit.conf b/monit.conf index 98c6484..c05a02e 100644 --- a/monit.conf +++ b/monit.conf @@ -1,3 +1,7 @@ check process api with pidfile /srv/http/tmp/puma.pid start program = "/usr/bin/entrypoint api" as uid app stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'" + +check process static with pidfile /tmp/darkhttpd.pid + start program = "/usr/bin/entrypoint darkhttpd" + stop program = "/bin/sh -c 'cat /tmp/darkhttpd.pid | xargs kill'"