ryohashimoto / lightrails Goto Github PK
View Code? Open in Web Editor NEWProvide more modular structures for Ruby on Rails applications
License: MIT License
Provide more modular structures for Ruby on Rails applications
License: MIT License
No more manual publishing.
Provide test helper module (methods) for facade / interactor / representer
class ArchivesController < ApplicationController
def day
# guess facade automatically
retrieve_facade :year, :month, :day, :pager, :posts
# instead of below:
# facade = Archives::DayFacade.new(params)
# retrieve facade, :year, :month, :day, :pager, :posts
end
Instead of the example below, it's useful if we can run bin/rails generate lightrails:install
command.
$ bin/rails generate action_facade:install
$ bin/rails generate action_interactor:install
$ bin/rails generate active_representer:install
It would be useful if result[:item_name]
can be accessed by result.item_name
.
class RegistrationInteractor < ActionInteractor::Base
attr_result :user # user is given after execution
...
registration = RegistrationInteractor.execute(name: 'John')
user = interactor.user # same as interactor.result[:user]
add USAGE files.
Add gemspec for Rubygems dependencies
Provide rake (rails) tasks for Rails project.
$ rails active_representer:install
create app/representers
create app/representers/application_representer.rb
$ rails action_interactor:install
create app/interactors
create app/interactors/application_interactor.rb
class Mypage::IndexFacade < ApplicationFacade
attr_reader :current_user
def initialize(params)
@current_user = params[:current_user]
end
def active_users
@active_users ||= User.active.order(login_at: :desc).limit(10)
end
def messages
@messages ||= current_user.messages.order(created_at: :desc).limit(10)
end
end
# in MypageController
def index
facade = Mypage::IndexFacade.new(current_user: current_user)
# instead of:
# @active_users = facade.active_users
# @messages = facade.messages
retrieve facade, :active_users, :messages
end
class ActiveRepresenter::Base
include ActiveModel::Model
include ActiveModel::Attributes
end
class Song < ActiveRepresenter::Base
attribute :title, :string
attribute :published, :boolean, default: true
end
It can be used like helper, but only valid in the namespace.
module MypageBacker # backer or another good name
extend ActionBacker::Base
def method_a
...
end
end
ActionBacker::Base
module is like ActiveSupport::Concerns
/app/views/mypage
but it can't be used for templates in other directories.module ApplicationBacker
extend ActionBacker::Base
include MypageBacker
end
Like roar, representer can render JSON for containing object.
song = Song.new(title: "Medicine Balls")
SongRepresenter.new(song).to_json #=> {"title":"Medicine Balls"}
If memonize :method_name
is added, automatically add @method_name ||=
to each method.
class Mypage::IndexFacade < ApplicationFacade
attr_reader :current_user
memoize :active_user, :messages
def initialize(params)
@current_user = params[:current_user]
end
def active_user
User.active.order(login_at: :desc).limit(10)
# same as below if memonize :active_user is set
# @active_user ||= User.active.order(login_at: :desc).limit(10)
end
def messages
current_user.messages.order(created_at: :desc).limit(10)
# same as below if memonize :messages is set
# @messages ||= current_user.messages.order(created_at: :desc).limit(10)
end
end
use results
method like this.
class RegistrationInteractor < ApplicationInteractor
def execute
return fail! unless params[:name]
results(
user: User.new(name: params[:name]),
activities: [Activity.new(title: 'Registration completed.']
)
success!
end
end
For reference manual
class AlbumRepresenter < ActiveRepresenter::Base
attr_collection :songs, representer: SongRepresenter
end
album = Album.new(title: "Scary Monsters", songs: [{title: "It's No Game"}, {title: "Up the Hill Backwards"}])
representer = AlbumRepresenter.new(album)
representer.songs.first.class # => SongRepresenter (automatically converted to a representer)
like finish!
(succcess!
and complete!
)
Dependabot can't resolve your Ruby dependency files.
As a result, Dependabot couldn't update your dependencies.
The error Dependabot encountered was:
Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
In Gemfile:
Ruby (~> 2.4.10.0)
lightrails was resolved to 0.2.5, which depends on
railties (>= 6.1.3.1, <= 6.1.3.2) was resolved to 6.1.3.2, which depends on
Ruby (>= 2.5.0)
If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.
In order to render response defined in JSON:API, use render_representer in controllers.
add concerns directory for facades / interactors /representers
Add ability to compose sub interactors in a parent interactor.
leader_interactor = LeaderInteractor.new
buyer_interactor = BuyerInteractor.new
cook_interactor = CookInteractor.new
arranger_interactor = ArrangerInteractor.new
leader_interactor.add_interactor(buyer_interactor)
leader_interactor.add_interactor(cook_interactor)
leader_interactor.add_interactor(arranger_interactor)
leader_interactor.execute
leader_interactor.succcessful? # => true
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.