Coder Social home page Coder Social logo

dbt's Introduction

DBT

DBT (Dependencies and deBugging Tool) is a RubyMotion tool that works for iOS, OSX, and Android to detect classes and dependencies. It will declare them in your config so you don't have to manually manage them.

iOS/OSX Dependency Analysis

DBT will look for break, require, and provides commands (and does a teensy bit of code analyzing - it will detect VERY basic class and module declarations) to make your RubyMotion debugger_cmds file easy to create, and declaring your file dependencies stupid simple.

CAUTION: It overwrites the debugger_cmds file!

To use, include this gem (gem 'dbt'), and add DBT.analyze(app) to your Rakefile, after you have added your own files to app.files. It looks at app.files and scans those files, so I mean it when I say "after you have added your own files". In your source code you add DBT commands:

# @provides Foo
# @requires module:Bar
class Foo
  include Bar

  def scary_method
#-----> break
    doing
    interesting
    stuff
  end

end

When you run rake, these commands will be found and translated into directives for app.files_dependencies and debugger_cmds. Run rake or rake debug=1, and off you go!

Your files will be grep'd for ^\w*(class|module), and these will be registered automatically as:

# you DON'T need to add these 'provides' lines!
# @provides class:ClassName
class ClassName
end

# @provides module:ModuleName
module ModuleName
end


# @provides module:Foo
module Foo
  # Sorry, no support for Foo::Bar... I do intend to add it, though!
  #
  # @provides class:Bar
  class Bar
  end
end


# ...in another file...
# @requires class:ClassName
# @requires module:ModuleName
class AnotherClass < ClassName
  include ModuleName
end

So right out of the box, you can add # @requires class:Foo if you're having trouble with dependencies and want a quick fix without having to add # @provides declarations all over the place.

Which begs the question, when would you need to declare an explicit # @provides? Examples:

Splitting up a class across multiple files:
controller.rb
# @provides Controller
class Controller < UIViewController
end
controller_table_view.rb
# provides table view methods
#
# @requires Controller
class Controller

  def numberOfSectionsInTableView(table_view)
    1
  end

end
Not-easily-greppable syntax
# @provides module:Foo::Bar
module Foo ; module Bar
end end

Android

In Android, dependencies are handled automatically, but you need to declare your Android::App::Activity classes in your config. Normally, you'd do something like this:

app.sub_activities = [
  "FirstActivity",
  "SecondActivity",
  # etc
]

With DBT, you can now add these declarations to the top of your activities:

# @activity FirstActivity
class FirstActivity < Android::App::Activity
  # ...
end

That's all the functionality we have for Android at the moment, but it's pretty helpful!

Breakpoints

Breakpoints are created using the syntax #--> break, with two or more dashes before the >. There must not be any whitespace before or after the #.

  def method
    do_something
#---> break
    do_dangerous_thing
  end

# you can also provide a line number
#--------> break 102
101:   def method
102:     do_something
103:     do_dangerous_thing
104:   end

If a line number is given to the break command, a breakpoint will be added at that line, otherwise it will be added to the line below break. It's better to insert the #--> break where you NEED it, rather than hardcode line numbers, since line numbers are not constant.

Running Tests

We have two simple test files, so just run them manually.

$ ruby spec/ios_spec.rb && ruby spec/android_spec.rb

dbt's People

Contributors

colinta avatar jamonholmgren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jamonholmgren

dbt's Issues

I don't mean to be ANAL...

This is a really terrific idea. And you built a working version in a jiffy.

Buddy, YOU JUST GOTTA CHANGE THE NAME!!

Whenever I read that clever aggregate name, my mind parses it as ANAL followed by a bunch of other letters

Convert to using Ripper for static analysis

I recommend we convert to using Ripper for static analysis, only using dbt directives if they're present.

2.0.0-p0 :001 > require 'ripper'
=> true
2.0.0-p0 :002 > r = Ripper.sexp(File.new('lib/motion-kit/layouts/view_layout.rb'), 'view_layout.rb')
=> [:program, [[:module, [:const_ref, [:@const, "MotionKit", [3, 7]]], [:bodystmt, [[:void_stmt], [:class, [:c

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.