Class: Undies::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/undies/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Source

Returns a new instance of Source.



7
8
9
10
11
# File 'lib/undies/source.rb', line 7

def initialize(*args, &block)
  named = args.first.kind_of?(NamedSource) ? args.first : nil
  args << block if block
  self.args = named ? named.args.compact : args
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/undies/source.rb', line 5

def data
  @data
end

#layoutObject

Returns the value of attribute layout.



5
6
7
# File 'lib/undies/source.rb', line 5

def layout
  @layout
end

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/undies/source.rb', line 5

def source
  @source
end

Instance Method Details

#==(other_source) ⇒ Object



29
30
31
32
# File 'lib/undies/source.rb', line 29

def ==(other_source)
  self.source == other_source.source &&
  self.layout_sources == other_source.layout_sources
end

#args=(values) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/undies/source.rb', line 34

def args=(values)
  proc, opts, file = [
    values.last.kind_of?(::Proc)   ? values.pop : nil,
    values.last.kind_of?(::Hash)   ? values.pop : {},
    values.last.kind_of?(::String) ? values.pop : nil
  ]

  self.source = file || proc
  self.layout = opts[:layout]
end

#file?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/undies/source.rb', line 13

def file?
  !@source.kind_of?(::Proc)
end

#layout_sourcesObject



25
26
27
# File 'lib/undies/source.rb', line 25

def layout_sources
  self.layouts.collect{|l| l.source}
end

#layoutsObject



17
18
19
20
21
22
23
# File 'lib/undies/source.rb', line 17

def layouts
  if layout
    [self.layout, self.layout.layouts].flatten.compact
  else
    []
  end
end