Module: TinyRails::Actions
- Included in:
- Commands::Add, Commands::Console, Commands::New
- Defined in:
- lib/tiny-rails/actions.rb
Overview
Kinda based on Rails’ github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb
Instance Method Summary collapse
- #addon(path) ⇒ Object
-
#application(data = nil, &block) ⇒ Object
Appends a line inside the TinyRailsApp class on boot.rb.
-
#enable_asset_pipeline! ⇒ Object
Self explanatory :P.
-
#gem(*args) ⇒ Object
Adds an entry into Gemfile for the supplied gem.
- #initializer(data) ⇒ Object
- #migration(data) ⇒ Object
- #route(new_route) ⇒ Object
Instance Method Details
#addon(path) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/tiny-rails/actions.rb', line 84 def addon(path) path = if URI(path).is_a?(URI::HTTP) path elsif File.exist? "#{self.class.bundled_addons_path}/#{path}.rb" "#{self.class.bundled_addons_path}/#{path}.rb" else File.(path) end unless applied_addons.include?(path) applied_addons << path apply(path) end end |
#application(data = nil, &block) ⇒ Object
Appends a line inside the TinyRailsApp class on boot.rb.
application do
"config.assets.enabled = true"
end
40 41 42 43 44 45 46 47 |
# File 'lib/tiny-rails/actions.rb', line 40 def application(data=nil, &block) data = block.call if !data && block_given? data = "\n#{data}" unless data =~ /^\n/ data << "\n" unless data =~ /\n$/ inject_into_file 'boot.rb', data, :after => /^ config\.secret_token = .+\n/ end |
#enable_asset_pipeline! ⇒ Object
Self explanatory :P
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/tiny-rails/actions.rb', line 72 def enable_asset_pipeline! return if File.read('boot.rb') =~ /^ config\.assets\.enabled = true$/ application <<-CONFIG # Enable asset pipeline config.assets.enabled = true config.assets.debug = true config.assets.paths << File.dirname(__FILE__) CONFIG inject_into_file 'boot.rb', "\nrequire \"sprockets/railtie\"", :after => /require ['"]action_controller\/railtie['"]/ end |
#gem(*args) ⇒ Object
Adds an entry into Gemfile for the supplied gem.
gem "rspec", group: :test
gem "technoweenie-restful-authentication", lib: "restful-authentication", source: "http://gems.github.com/"
gem "rails", "3.0", git: "git://github.com/rails/rails"
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tiny-rails/actions.rb', line 9 def gem(*args) = (args) name, version = args # Set the message to be shown in logs. Uses the git repo if one is given, # otherwise use name (version). parts, = [ name.inspect ], name if version ||= .delete(:version) parts << version.inspect << " (#{version})" end = [:git] if [:git] say_status :gemfile, .each do |option, value| parts << "#{option}: #{value.inspect}" end in_root do str = "gem #{parts.join(", ")}" str = "\n" + str append_file "Gemfile", str, :verbose => false end end |
#initializer(data) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/tiny-rails/actions.rb', line 49 def initializer(data) data = open(data) { |io| io.read } if data =~ /https?:\/\// if File.exists? 'initializers.rb' append_file 'initializers.rb', "\n#{data}" else create_file 'initializers.rb', data end end |
#migration(data) ⇒ Object
59 60 61 62 63 |
# File 'lib/tiny-rails/actions.rb', line 59 def migration(data) data << "\n" unless data =~ /\n$/ inject_into_file 'migrate', data, :after => /^ActiveRecord::Schema\.define do\n/ end |
#route(new_route) ⇒ Object
65 66 67 68 69 |
# File 'lib/tiny-rails/actions.rb', line 65 def route(new_route) new_route << "\n" unless new_route =~ /\n$/ inject_into_file 'boot.rb', new_route, :after => /TinyRailsApp\.routes\.draw do\n/ end |