Module: ViewMapper

Defined in:
lib/view_mapper/model_info.rb,
lib/view_mapper/view_mapper.rb,
lib/view_mapper/route_action.rb,
lib/view_mapper/has_many_child_models.rb,
lib/view_mapper/belongs_to_parent_models.rb,
lib/view_mapper/views/has_many/has_many_view.rb,
lib/view_mapper/views/paperclip/paperclip_view.rb,
lib/view_mapper/views/belongs_to/belongs_to_view.rb,
lib/view_mapper/views/auto_complete/auto_complete_view.rb,
lib/view_mapper/views/has_many_existing/has_many_existing_view.rb,
lib/view_mapper/views/belongs_to_auto_complete/belongs_to_auto_complete_view.rb

Defined Under Namespace

Modules: AutoCompleteView, BelongsToAutoCompleteView, BelongsToParentModels, BelongsToView, HasManyChildModels, HasManyExistingView, HasManyView, PaperclipView, RouteAction Classes: ModelInfo

Instance Method Summary collapse

Instance Method Details

#add_options!(opt) ⇒ Object



43
44
45
46
47
48
# File 'lib/view_mapper/view_mapper.rb', line 43

def add_options!(opt)
  opt.on("--view name", String, "Specify a view to generate") do |name|
    options[:view] = name
  end
  super
end

#initialize(runtime_args, runtime_options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/view_mapper/view_mapper.rb', line 3

def initialize(runtime_args, runtime_options = {})
  Rails::Generator::Commands::Base.class_eval { include RouteAction::Base }
  Rails::Generator::Commands::Create.class_eval { include RouteAction::Create }
  Rails::Generator::Commands::Destroy.class_eval { include RouteAction::Destroy }
  super
  self.extend(view_module) if options[:view]
end

#source_path(relative_source) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/view_mapper/view_mapper.rb', line 11

def source_path(relative_source)
  if options[:view]
    source_roots_for_view.map do |source_root|
      File.join(File.expand_path(source_root), relative_source)
    end.detect do |path|
      File.exists? path
    end
  else
    super
  end
end

#source_roots_for_viewObject



23
24
25
# File 'lib/view_mapper/view_mapper.rb', line 23

def source_roots_for_view
  [ view_module.source_root, File.expand_path(source_root) ]
end

#view_moduleObject



27
28
29
# File 'lib/view_mapper/view_mapper.rb', line 27

def view_module
  "ViewMapper::#{view_name.camelize}View".constantize
end

#view_nameObject



31
32
33
# File 'lib/view_mapper/view_mapper.rb', line 31

def view_name
  options[:view].split(':')[0]
end

#view_only?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/view_mapper/view_mapper.rb', line 39

def view_only?
  self.respond_to?(:model)
end

#view_paramObject



35
36
37
# File 'lib/view_mapper/view_mapper.rb', line 35

def view_param
  options[:view].split(':')[1]
end