Module: Cyborg

Extended by:
Cyborg
Included in:
Cyborg
Defined in:
lib/cyborg.rb,
lib/cyborg/assets.rb,
lib/cyborg/plugin.rb,
lib/cyborg/command.rb,
lib/cyborg/version.rb,
lib/cyborg/middleware.rb,
lib/cyborg/command/npm.rb,
lib/cyborg/config_data.rb,
lib/cyborg/command/help.rb,
lib/cyborg/sass/importer.rb,
lib/cyborg/command/scaffold.rb,
lib/cyborg/plugin/assets/svgs.rb,
lib/cyborg/plugin/assets/asset.rb,
lib/cyborg/helpers/asset_helpers.rb,
lib/cyborg/helpers/layout_helpers.rb,
lib/cyborg/plugin/assets/javascripts.rb,
lib/cyborg/plugin/assets/stylesheets.rb

Defined Under Namespace

Modules: Assets, Command, ConfigData, Help, Helpers, NPM, SassParser Classes: Application, Importer, Plugin, Scaffold, StaticAssets

Constant Summary collapse

VERSION =
"0.7.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pluginObject

Returns the value of attribute plugin.



15
16
17
# File 'lib/cyborg.rb', line 15

def plugin
  @plugin
end

Instance Method Details

#at_gem_rootObject



58
59
60
# File 'lib/cyborg.rb', line 58

def at_gem_root
  !Dir['*.gemspec'].empty?
end

#at_rails_rootObject



54
55
56
# File 'lib/cyborg.rb', line 54

def at_rails_root
  File.exist?("bin/rails")
end

#config_dataObject



30
31
32
# File 'lib/cyborg.rb', line 30

def config_data
  Cyborg::ConfigData.read(Cyborg.plugin.root, Rails.root)
end

#gem_pathObject



62
63
64
65
66
67
68
# File 'lib/cyborg.rb', line 62

def gem_path
  if at_gem_root
    Dir.pwd
  elsif at_rails_root
    "../"
  end
end

#load_helpersObject



44
45
46
47
48
49
50
51
52
# File 'lib/cyborg.rb', line 44

def load_helpers
  require "cyborg/helpers/asset_helpers"
  require "cyborg/helpers/layout_helpers"

  Cyborg::Helpers.constants.each do |c|
    helper = Cyborg::Helpers.const_get(c)
    ActionView::Base.send :include, helper if defined? ActionView::Base
  end
end

#patch_railsObject



40
41
42
# File 'lib/cyborg.rb', line 40

def patch_rails
  load_helpers
end

#production?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/cyborg.rb', line 18

def production?
  ENV['CI'] || ENV['RAILS_ENV'] == 'production' || Command.production?
end

#rails5?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/cyborg.rb', line 22

def rails5?
 Gem::Version.new(Rails.version) >= Gem::Version.new('5') 
end

#rails_path(sub = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cyborg.rb', line 70

def rails_path(sub=nil)
  path = if at_rails_root
    Dir.pwd
  else
    dir = Dir["**/bin/rails"]
    if !dir.empty?
      dir.first.split('/').first
    end
  end
  path = File.join(path, sub) if sub
  path
end

#register(plugin_module, options = {}, &block) ⇒ Object



34
35
36
37
38
# File 'lib/cyborg.rb', line 34

def register(plugin_module, options={}, &block)
  @plugin = plugin_module.new(options)
  @plugin.create_engine(&block)
  patch_rails
end