Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating badges implementaiton architecture
- Loading branch information
1 parent
3a7b30b
commit b6353f4
Showing
11 changed files
with
189 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
source "https://rubygems.org" | ||
gemspec | ||
|
||
gem "rails", "~> 5.0.0" | ||
gem "rspec", "~> 3.5.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
machine: | ||
ruby: | ||
version: 2.2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "gioco/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'gioco' | ||
s.version = File.read(File.dirname(__FILE__) + '/VERSION').strip | ||
s.date = '2016-07-13' | ||
s.summary = 'A gamification gem for Ruby on Rails applications.' | ||
s.description = 'Gioco is a gem to easly implement gamification.' | ||
s.name = "gioco" | ||
s.version = Gioco::VERSION.dup | ||
s.date = "2016-07-13" | ||
s.platform = Gem::Platform::RUBY | ||
s.summary = "A gamification gem for Ruby on Rails applications." | ||
s.description = "Gioco is a gem to easly implement gamification." | ||
s.authors = ["João Moura"] | ||
s.email = 'joaomdmoura@gmail.com' | ||
s.files = Dir[ 'lib/*' ] | ||
s.homepage = 'https://github.com/GiocoApp/gioco' | ||
s.license = 'MIT' | ||
s.add_development_dependency 'rspec' | ||
s.email = "joaomdmoura@gmail.com" | ||
s.files = Dir["lib"] | ||
s.homepage = "https://github.com/joaomdmoura/gioco" | ||
s.licenses = ["MIT"] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## | ||
# ModelGeneratorHelper is a helper that contains all method and logic related | ||
# the the model generation and relationships definitions when running gioco generator. | ||
|
||
module ModelGeneratorHelper | ||
|
||
# Responsible for creating the new models and adding relationships. | ||
# | ||
# ==== Attributes | ||
# | ||
# * +options+ - A Hash containing the generators options passed on GiocoGenerator | ||
# | ||
def setup_models(options) | ||
setup_badges if options[:badges] | ||
end | ||
|
||
private | ||
|
||
# Creates all badges related model, migrations and injections. | ||
def setup_badges | ||
generate("model", "badge name:string") | ||
generate("migration", "create_badges_and_#{model.pluralize} badge:references #{model}:references") | ||
add_relationship("badge", model.pluralize, "has_and_belongs_to_many") | ||
add_relationship(model, "badges", "has_and_belongs_to_many") | ||
end | ||
|
||
# Helper method for easly inject relationships into models classes. | ||
def add_relationship (model, related, relation) | ||
inject_into_class "app/models/#{model}.rb", model.capitalize, "#{relation} :#{related}\n" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
## | ||
# This is Gioco main class, it's the first loaded when requiring gioco | ||
|
||
class Gioco | ||
module Gioco | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Gioco | ||
VERSION = "2.0.0".freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "generators/gioco_generator" | ||
|
||
RSpec.describe GiocoGenerator do | ||
describe "#execute" do | ||
let(:model) { 'user'.freeze } | ||
|
||
context 'setting up gioco with badges architecture' do | ||
let(:subject) { GiocoGenerator.new([ model ], badges: true) } | ||
|
||
it "generates the badges model and inject the relationships" do | ||
allow(subject).to receive(:inject_into_class) | ||
|
||
expect(subject).to receive(:generate).with("model", "badge name:string") | ||
expect(subject).to receive(:generate).with("migration", "create_badges_and_#{model.pluralize} badge:references #{model}:references") | ||
expect(subject).to receive(:inject_into_class).with("app/models/badge.rb", 'Badge', "has_and_belongs_to_many :users\n") | ||
expect(subject).to receive(:inject_into_class).with("app/models/#{model}.rb", model.capitalize, "has_and_belongs_to_many :badges\n") | ||
|
||
subject.execute | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters