documentación

This commit is contained in:
fauno 2019-04-06 17:41:44 -03:00
parent 94fbf70cd8
commit 4875a770ac
No known key found for this signature in database
GPG key ID: 456032D717A4CD9C
17 changed files with 164 additions and 10 deletions

View file

@ -3,7 +3,6 @@ node_modules/
tmp/ tmp/
log/ log/
public/ public/
docs/
bin/ bin/
db/ db/
lib/ lib/

3
.gitignore vendored
View file

@ -27,3 +27,6 @@
/config/master.key /config/master.key
# Siempre da conflictos # Siempre da conflictos
/db/schema.rb /db/schema.rb
/public/docs/
/.yardoc/
/docs/

View file

@ -33,7 +33,7 @@ RUN git archive -o ../web.tar.gz HEAD
FROM lunar/monit:3.9 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 libxslt libxml2 tzdata ruby ruby-bundler ruby-json ruby-bigdecimal ruby-rake
RUN apk add --no-cache sqlite sqlite-libs 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 COPY ./entrypoint.sh /usr/bin/entrypoint
RUN chmod 755 /usr/bin/entrypoint RUN chmod 755 /usr/bin/entrypoint
# Agregar el usuario # Agregar el usuario
@ -46,9 +46,11 @@ RUN tar xf /tmp/web.tar.gz && rm /tmp/web.tar.gz
# Traer las gemas # 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/vendor ./vendor
COPY --from=build --chown=app:www-data /home/app/web/.bundle ./.bundle COPY --from=build --chown=app:www-data /home/app/web/.bundle ./.bundle
COPY --chown=app:www-data ./docs ./public/docs
USER root USER root
RUN install -m 640 -o root -g root ./monit.conf /etc/monit.d/puma.conf RUN install -m 640 -o root -g root ./monit.conf /etc/monit.d/puma.conf
RUN monit -t RUN monit -t
VOLUME "/srv/http/public/system" VOLUME "/srv/http/data"
EXPOSE 3000 EXPOSE 3000
EXPOSE 8080

View file

@ -40,6 +40,7 @@ group :development do
gem 'rubocop' gem 'rubocop'
gem 'spring' gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0' gem 'spring-watcher-listen', '~> 2.0.0'
gem 'yard'
end end
group :test do group :test do

View file

@ -160,6 +160,7 @@ GEM
websocket-driver (0.7.0) websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3) websocket-extensions (0.1.3)
yard (0.9.19)
PLATFORMS PLATFORMS
ruby ruby
@ -179,6 +180,7 @@ DEPENDENCIES
spring spring
spring-watcher-listen (~> 2.0.0) spring-watcher-listen (~> 2.0.0)
sqlite3 sqlite3
yard
RUBY VERSION RUBY VERSION
ruby 2.5.3p105 ruby 2.5.3p105

View file

@ -5,6 +5,11 @@ c ?= $(shell date +%F | tr "-" ".")
r ?= $(shell git rev-list --count HEAD) r ?= $(shell git rev-list --count HEAD)
name = miniloom/$(d):$(c).$(r) name = miniloom/$(d):$(c).$(r)
doc:
./bin/yardoc --output-dir=./docs/ \
app/controllers/*.rb \
app/models/*.rb
clean: clean:
rm -f log/*.log rm -f log/*.log
rm -rf tmp/cache/assets 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/$(name)
docker push registry.forja.lainventoria.com.ar/miniloom/$(d):latest docker push registry.forja.lainventoria.com.ar/miniloom/$(d):latest
all: clean build tag push all: clean doc build tag push

View file

@ -1,15 +1,29 @@
# frozen_string_literal: true # frozen_string_literal: true
# Consensos # API para Consensos, necesita autenticar una pirata vía HTTP Basic Auth
#
# @see PiratasController#create
class ConsensosController < ApplicationController class ConsensosController < ApplicationController
# Para cualquier acción necesitamos autenticación
before_action :authenticate! before_action :authenticate!
# GET /consensos
#
# Podemos ver todos los consensos # Podemos ver todos los consensos
#
# @return [Array] [ consensos ]
def index def index
@consensos = Consenso.all.order(:created_at, :desc) @consensos = Consenso.all.order(:created_at, :desc)
end 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 def show
@consenso = Consenso.find(params[:id]) @consenso = Consenso.find(params[:id])
return if @consenso return if @consenso
@ -17,7 +31,14 @@ class ConsensosController < ApplicationController
render json: {}, status: :not_found render json: {}, status: :not_found
end 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 def create
@consenso = current_pirata.consensos @consenso = current_pirata.consensos
.new(params.require(:consenso).permit(:titulo, :texto)) .new(params.require(:consenso).permit(:titulo, :texto))

View file

@ -2,7 +2,13 @@
# Las piratas son las que activan el Miniloom # Las piratas son las que activan el Miniloom
class PiratasController < ApplicationController class PiratasController < ApplicationController
# POST /piratas
#
# Registra una cuenta # Registra una cuenta
#
# @param pirata [Hash] { pirata: { password: @string, email: @string,
# nick: @string } }
# @return [Hash] { id: @int, nick: @string, email: @string }
def create def create
@pirata = Pirata.new(params @pirata = Pirata.new(params
.require(:pirata) .require(:pirata)

View file

@ -1,9 +1,21 @@
# frozen_string_literal: true # frozen_string_literal: true
# API para posiciones
#
# Las posiciones solo se pueden agregar a su consenso # Las posiciones solo se pueden agregar a su consenso
#
# @see PiratasController#create
class PosicionesController < ApplicationController class PosicionesController < ApplicationController
# Necesitamos autenticarnos
before_action :authenticate! 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 def create
@consenso = Consenso.find(params[:consenso_id]) @consenso = Consenso.find(params[:consenso_id])
@posicion = @consenso.try(:posiciones).try(:build, posicion_params) @posicion = @consenso.try(:posiciones).try(:build, posicion_params)

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
# El consenso agrupa posiciones y textos # Los consensos son textos sobre los que las piratas establecen
# posiciones
class Consenso < ApplicationRecord class Consenso < ApplicationRecord
# Es escrito por una pirata # Es escrito por una pirata
belongs_to :pirata belongs_to :pirata

View file

@ -1,3 +1,3 @@
# frozen_string_literal: true # frozen_string_literal: true
json.call(@pirata, :nick, :email) json.call(@pirata, :id, :nick, :email)

29
bin/yard Executable file
View file

@ -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')

29
bin/yardoc Executable file
View file

@ -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')

29
bin/yri Executable file
View file

@ -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')

View file

@ -22,4 +22,4 @@ test:
production: production:
<<: *default <<: *default
database: db/production.sqlite3 database: data/production.sqlite3

View file

@ -10,4 +10,15 @@ case $1 in
bundle exec puma -d config.ru bundle exec puma -d config.ru
exit $? 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 esac

View file

@ -1,3 +1,7 @@
check process api with pidfile /srv/http/tmp/puma.pid check process api with pidfile /srv/http/tmp/puma.pid
start program = "/usr/bin/entrypoint api" as uid app start program = "/usr/bin/entrypoint api" as uid app
stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'" 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'"