gambiarra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bf62461a64d35d9c9b16215e03927c4a864b85056694b33f433886d8dc00e87e
4
+ data.tar.gz: 620d6b35662d3995249f5b99dce173551f5edca53ac7c6ea75b22b9da94a9cf4
5
+ SHA512:
6
+ metadata.gz: 955af1b5a59ab2b1d8dc4f8b0335183f393753e198c2d1094e9e599e740fe3627942c9762d9d880f10f5eae4c76d69935d102edd2d14018c8e652ebec7d21068
7
+ data.tar.gz: d43dbf6c22eaea27a57fc90b5fcbdbca371084c02c36af8d7a569382422cc816af64a1b862fff996109df92f8d1812a5db05482ad9e58329dde476e468e2dd53
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at pedrozath@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'pry-byebug'
4
+
5
+ group :test do
6
+ gem 'rspec'
7
+ gem 'simplecov', require: false
8
+ gem 'rubocop', require: false
9
+ end
10
+
11
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,88 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gambiarra (0.0.1)
5
+ activesupport (> 5.2)
6
+ cli-ui (~> 1.1)
7
+ thor (= 0.20)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.2.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ ast (2.4.0)
18
+ byebug (10.0.2)
19
+ cli-ui (1.1.4)
20
+ coderay (1.1.2)
21
+ concurrent-ruby (1.0.5)
22
+ diff-lcs (1.3)
23
+ docile (1.3.1)
24
+ i18n (1.1.1)
25
+ concurrent-ruby (~> 1.0)
26
+ jaro_winkler (1.5.1)
27
+ json (2.1.0)
28
+ method_source (0.9.0)
29
+ minitest (5.11.3)
30
+ parallel (1.12.1)
31
+ parser (2.5.1.2)
32
+ ast (~> 2.4.0)
33
+ powerpack (0.1.2)
34
+ pry (0.11.3)
35
+ coderay (~> 1.1.0)
36
+ method_source (~> 0.9.0)
37
+ pry-byebug (3.6.0)
38
+ byebug (~> 10.0)
39
+ pry (~> 0.10)
40
+ rainbow (3.0.0)
41
+ rake (10.5.0)
42
+ rspec (3.7.0)
43
+ rspec-core (~> 3.7.0)
44
+ rspec-expectations (~> 3.7.0)
45
+ rspec-mocks (~> 3.7.0)
46
+ rspec-core (3.7.1)
47
+ rspec-support (~> 3.7.0)
48
+ rspec-expectations (3.7.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.7.0)
51
+ rspec-mocks (3.7.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.7.0)
54
+ rspec-support (3.7.1)
55
+ rubocop (0.59.2)
56
+ jaro_winkler (~> 1.5.1)
57
+ parallel (~> 1.10)
58
+ parser (>= 2.5, != 2.5.1.1)
59
+ powerpack (~> 0.1)
60
+ rainbow (>= 2.2.2, < 4.0)
61
+ ruby-progressbar (~> 1.7)
62
+ unicode-display_width (~> 1.0, >= 1.0.1)
63
+ ruby-progressbar (1.10.0)
64
+ simplecov (0.16.1)
65
+ docile (~> 1.1)
66
+ json (>= 1.8, < 3)
67
+ simplecov-html (~> 0.10.0)
68
+ simplecov-html (0.10.2)
69
+ thor (0.20.0)
70
+ thread_safe (0.3.6)
71
+ tzinfo (1.2.5)
72
+ thread_safe (~> 0.1)
73
+ unicode-display_width (1.4.0)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ bundler (~> 1.16)
80
+ gambiarra!
81
+ pry-byebug
82
+ rake (~> 10.0)
83
+ rspec
84
+ rubocop
85
+ simplecov
86
+
87
+ BUNDLED WITH
88
+ 1.16.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Pedro Maciel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Gambiarra
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gambiarra`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gambiarra'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gambiarra
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gambiarra. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Gambiarra project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gambiarra/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/gambiarra ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
4
+
5
+ require 'gambiarra/ui'
6
+
7
+ module Gambiarra
8
+ module UI
9
+ class App < Gambiarra::App
10
+
11
+ end
12
+ end
13
+ end
14
+
15
+ Gambiarra::UI::App.start(ARGV.join(' '))
data/gambiarra.gemspec ADDED
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gambiarra/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gambiarra"
8
+ spec.version = Gambiarra::VERSION
9
+ spec.authors = ["Pedro Maciel"]
10
+ spec.email = ["pedrozath@gmail.com"]
11
+
12
+ spec.summary = %q{An intuitive framework for CLI applications}
13
+ spec.homepage = "https://github.com/pedrozath/gambiarra"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_runtime_dependency 'thor', '0.20'
29
+ spec.add_runtime_dependency 'cli-ui', '~> 1.1'
30
+ spec.add_runtime_dependency 'activesupport', '> 5.2'
31
+
32
+ end
data/lib/.DS_Store ADDED
Binary file
data/lib/gambiarra.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'active_support/inflector'
2
+ require 'cli/ui'
3
+
4
+ require 'gambiarra/version'
5
+ require 'gambiarra/core_extensions'
6
+ require 'gambiarra/view'
7
+ require 'gambiarra/history'
8
+ require 'gambiarra/route'
9
+ require 'gambiarra/router'
10
+ require 'gambiarra/app'
11
+
Binary file
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gambiarra
4
+ class App
5
+ attr_reader :router, :debugging
6
+
7
+ class << self
8
+ attr_reader :app_class
9
+
10
+ def inherited(app_class)
11
+ @app_class = app_class
12
+ end
13
+ end
14
+
15
+ def self.start(initial_route='')
16
+ path, params = initial_route.split(' ').each_with_object([nil, {}]) do |segment, memo|
17
+ if segment =~ /:/
18
+ key, value = segment.split(':')
19
+ memo[1].merge!([[key.to_sym, value.gsub('-', ' ')]].to_h)
20
+ else
21
+ memo[0] = [memo[0], segment].compact.join(' ')
22
+ end
23
+ end
24
+
25
+ response = {path: (path || ''), **params}
26
+ loop { response = app.flow(**response) }
27
+ end
28
+
29
+ def self.app
30
+ @app ||= new
31
+ end
32
+
33
+ def initialize(debugging: false)
34
+ debugging = true
35
+ setup if respond_to?(:setup)
36
+ @debugging = debugging
37
+ @router = Router.new
38
+ end
39
+
40
+ def ask_questions(questions)
41
+ questions.map { |name, question| [name, ask_question(question)] }.to_h
42
+ end
43
+
44
+ def ask_question(question)
45
+ CLI::UI::Prompt.ask(question[:statement], options: question[:options])
46
+ end
47
+
48
+ def navigation(params)
49
+ return {} if params.empty?
50
+ CLI::UI::Prompt.ask('What to do now?') do |h|
51
+ params.each do |key, _value|
52
+ h.option("Different #{key}") { params[key] = nil }
53
+ end
54
+ h.option("Go back") { params[:path] = '' }
55
+ end
56
+ params
57
+ end
58
+
59
+ def output(response)
60
+ return unless response[:content]
61
+ puts [
62
+ nil,
63
+ "-> #{app_name} #{router.url}",
64
+ nil,
65
+ response[:content],
66
+ nil
67
+ ]
68
+ end
69
+
70
+ def app_name
71
+ self.class.to_s.split('::').first.underscore.gsub('_', '-')
72
+ end
73
+
74
+ def flow(response)
75
+ raise 'Response is empty' unless response
76
+ output(response)
77
+ response.delete(:content)
78
+ questions = response&.delete(:questions) || {}
79
+ response.merge!(navigation(response)) unless response.has_key?(:path) || questions.any?
80
+ response.merge!(ask_questions(questions)) if questions.any?
81
+ exit if response[:path] == 'exit'
82
+ router.get(**response.compact)
83
+ rescue => e
84
+ puts e.backtrace if debugging
85
+ puts e
86
+ response.delete(:path)
87
+ retry unless debugging
88
+ end
89
+
90
+ def exit
91
+ Kernel.exit(0)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,11 @@
1
+ module Gambiarra
2
+ module CoreExtensions
3
+ refine Hash do
4
+ def deep_dup
5
+ dup_hash = {}
6
+ each { |k, v| dup_hash[k] = v.is_a?(Hash) ? v.deep_dup : v.dup }
7
+ dup_hash
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ module Gambiarra
2
+ class History
3
+ attr_reader :routes
4
+
5
+ def initialize
6
+ @routes = []
7
+ end
8
+
9
+ def add(route)
10
+ @routes << route
11
+ end
12
+
13
+ def previous
14
+ routes[-2]&.path || ''
15
+ end
16
+
17
+ def current_route
18
+ routes[-1]
19
+ end
20
+
21
+ def back
22
+ routes.pop.respond
23
+ end
24
+
25
+ def refresh(params={})
26
+ return {
27
+ content: 'Abnormal end',
28
+ path: 'exit'
29
+ } unless current_route
30
+
31
+ current_route.respond(params)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ module Gambiarra
2
+ class Route
3
+ attr_reader :path, :view, :last
4
+ attr_accessor :params
5
+
6
+ def initialize(path, to:, with: {})
7
+ @path = path
8
+ @view = to
9
+ @params = with
10
+ end
11
+
12
+ def respond(**other_params)
13
+ view.respond(**params, **other_params)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,45 @@
1
+ module Gambiarra
2
+ class Router
3
+ attr_reader :path, :params, :routes, :history, :url
4
+
5
+ def initialize
6
+ @routes = []
7
+ @history = History.new
8
+
9
+ base_view = View.descendants[:BaseView]
10
+ draw_route '', to: base_view.descendants[:Index]
11
+ base_view.descendants.each do |name, view|
12
+ next if name == :Index
13
+ draw_route name.to_s.underscore.humanize.downcase, to: view
14
+ end
15
+ end
16
+
17
+ def get(**params)
18
+ path = params.delete(:path)
19
+ @url = build_url(path || history.current_route.path, **params)
20
+ route = routes.detect { |route| route.path == path }
21
+ return history.refresh(params) unless route
22
+ history.add(route)
23
+ route.respond(**params)
24
+ end
25
+
26
+ def previous_path
27
+ history.previous
28
+ end
29
+
30
+ private
31
+
32
+ def build_url(path, params)
33
+ [
34
+ path,
35
+ (params || {}).map do |k,v|
36
+ [k,v.gsub(' ', '-')].join(':')
37
+ end
38
+ ].compact.join(' ')
39
+ end
40
+
41
+ def draw_route(*args, **keyword_args, &block)
42
+ @routes << Route.new(*args, **keyword_args, &block)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ require 'thor'
2
+ require 'gambiarra'
3
+
4
+ require File.expand_path('../ui/base_view', __FILE__)
5
+ views = Dir[File.expand_path('../ui/views/*', __FILE__)].map { |view| require(view) }
Binary file
@@ -0,0 +1,23 @@
1
+ module Gambiarra
2
+ module UI
3
+ class BaseView < Gambiarra::View
4
+ def thor
5
+ @thor ||= begin
6
+ thor_class = Class.new(Thor::Group) do
7
+ include Thor::Actions
8
+ end
9
+ .tap { |t| t.source_root("#{Dir.pwd}") }
10
+ .new
11
+ end
12
+ end
13
+
14
+ def project_name
15
+ Dir.pwd.split('/').last
16
+ end
17
+
18
+ def project_constant
19
+ project_name.gsub('-', '_').camelize
20
+ end
21
+ end
22
+ end
23
+ end
Binary file
@@ -0,0 +1,34 @@
1
+ module Gambiarra
2
+ module UI
3
+ class CreateView < BaseView
4
+ questions(view_name: {
5
+ statement: 'Type the view name in a human way. Ex: "cook rice"' }
6
+ )
7
+
8
+ def render
9
+ view = params[:view_name].gsub(/ |_|-/, '_').downcase
10
+ thor.create_file("lib/#{project_name}/ui/views/#{view}.rb", <<~RUBY)
11
+ module #{project_constant}
12
+ module UI
13
+ # you can also inherit from your other views, questions will be merged
14
+ # assign them to nil to erase them
15
+ class #{view.camelize} < BaseView
16
+ questions({
17
+ question_name: {
18
+ statement: 'Welcome to #{project_name.titleize}',
19
+ options: ['exit'] # delete options to make this free form
20
+ }
21
+ })
22
+ end
23
+
24
+ def render
25
+ # might want render something here after questions are answered
26
+ end
27
+ end
28
+ end
29
+
30
+ RUBY
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ module Gambiarra
2
+ module UI
3
+ class Index < BaseView
4
+ questions({
5
+ path: {
6
+ statement: "Welcome to Gambiarra #{Gambiarra::VERSION}",
7
+ options: [
8
+ 'install',
9
+ 'create view',
10
+ 'exit'
11
+ ]
12
+ }
13
+ })
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,86 @@
1
+ module Gambiarra
2
+ module UI
3
+ class Install < BaseView
4
+ questions({
5
+ confirm_installation: {
6
+ statement: 'It will install Gambiarra on current folder. Are you sure?',
7
+ options: [
8
+ 'yes',
9
+ 'exit'
10
+ ]
11
+ }
12
+ })
13
+
14
+ def render
15
+ exit if params[:confirm_installation] == 'exit'
16
+ thor.empty_directory("lib/#{project_name}/ui/views")
17
+ thor.create_file("lib/#{project_name}/ui.rb", <<~RUBY)
18
+ require('gambiarra')
19
+ require File.expand_path('../ui/base_view', __FILE__)
20
+ views = Dir[File.expand_path('../ui/views/*', __FILE__)].each do |view|
21
+ require(view)
22
+ end
23
+
24
+ RUBY
25
+
26
+ thor.create_file("lib/#{project_name}/ui/base_view.rb", <<~RUBY)
27
+ module #{project_constant}
28
+ module UI
29
+ class BaseView < Gambiarra::View
30
+ def render(view)
31
+ view.render
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ RUBY
38
+
39
+ thor.create_file("lib/#{project_name}/ui/views/index.rb", <<~RUBY)
40
+ module #{project_constant}
41
+ module UI
42
+ class Index < BaseView
43
+ questions({
44
+ path: {
45
+ statement: 'Welcome to #{project_name.titleize}',
46
+ options: [
47
+ 'an option',
48
+ 'exit'
49
+ ]
50
+ }
51
+ })
52
+ end
53
+ end
54
+ end
55
+
56
+ RUBY
57
+
58
+ thor.create_file("exe/#{project_name.gsub('_', '-')}", <<~RUBY)
59
+ #!/usr/bin/env ruby
60
+ # frozen_string_literal: true
61
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
62
+
63
+ require '#{project_name}/ui'
64
+
65
+ module #{project_constant}
66
+ module UI
67
+ class App < Gambiarra::App
68
+ def setup
69
+ # you can setup stuff here
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ #{project_constant}::UI::App.start(ARGV.join(' '))
76
+
77
+ RUBY
78
+
79
+
80
+ thor.chmod("exe/#{project_name.gsub('_', '-')}", '+x')
81
+
82
+ "Installed Gambiarra in #{Dir.pwd}"
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module Gambiarra
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,58 @@
1
+ module Gambiarra
2
+ class View
3
+ using Gambiarra::CoreExtensions
4
+
5
+ attr_reader :params, :path
6
+
7
+ class << self
8
+ attr_reader :descendants
9
+ attr_accessor :parent
10
+
11
+ def inherited(subclass)
12
+ @descendants ||= {}
13
+ subclass.parent = self
14
+ new_descendant = { subclass.to_s.split('::').last.to_sym => subclass }
15
+ @descendants.merge!(new_descendant)
16
+ parent&.descendants&.merge!(new_descendant)
17
+ @questions ||= {}
18
+ subclass.instance_variable_set(:@questions, @questions.deep_dup)
19
+ end
20
+
21
+ def questions(question_data)
22
+ @questions.merge!(question_data)
23
+ @questions.compact!
24
+ end
25
+
26
+ def set_path(value)
27
+ @params[:path] = value
28
+ end
29
+
30
+ def respond(**params)
31
+ remaining_questions = @questions.slice(*(@questions.keys - params.keys))
32
+ return { questions: remaining_questions, **params } if remaining_questions.any?
33
+ view = new(**params)
34
+ { content: render(view), **params }
35
+ end
36
+
37
+ def render(view)
38
+ view.render
39
+ end
40
+ end
41
+
42
+ def initialize(**params)
43
+ @params = params
44
+ end
45
+
46
+ def output(object)
47
+ self.class.output(object)
48
+ end
49
+
50
+ def go_to(path, **params)
51
+ # App.router.set_next(path, **params) and return
52
+ end
53
+
54
+ def ensure_param(param_name, &block)
55
+ @params[param_name] = block.call if @params[param_name].nil?
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gambiarra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Maciel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: '0.20'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: '0.20'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cli-ui
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.2'
97
+ description:
98
+ email:
99
+ - pedrozath@gmail.com
100
+ executables:
101
+ - gambiarra
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".DS_Store"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/setup
116
+ - exe/gambiarra
117
+ - gambiarra.gemspec
118
+ - lib/.DS_Store
119
+ - lib/gambiarra.rb
120
+ - lib/gambiarra/.DS_Store
121
+ - lib/gambiarra/app.rb
122
+ - lib/gambiarra/core_extensions.rb
123
+ - lib/gambiarra/history.rb
124
+ - lib/gambiarra/route.rb
125
+ - lib/gambiarra/router.rb
126
+ - lib/gambiarra/ui.rb
127
+ - lib/gambiarra/ui/.DS_Store
128
+ - lib/gambiarra/ui/base_view.rb
129
+ - lib/gambiarra/ui/views/.DS_Store
130
+ - lib/gambiarra/ui/views/create_view.rb
131
+ - lib/gambiarra/ui/views/index.rb
132
+ - lib/gambiarra/ui/views/install.rb
133
+ - lib/gambiarra/version.rb
134
+ - lib/gambiarra/view.rb
135
+ homepage: https://github.com/pedrozath/gambiarra
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.7.6
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: An intuitive framework for CLI applications
159
+ test_files: []